Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I draw a line across a div, over text, without displacing the text?

I have a series of square divs with text in them, and I need to draw a line across those divs, over the text. Z-Index is not an option. Neither is <strike>, because it needs to extend across the entire div, not just the text.

What I need is for it to extend across the entire div, but to be ON TOP of the text, as if on a different layer, and I am trying to determine if it is possible without Z-Index.

like image 363
user1790093 Avatar asked Jan 11 '13 17:01

user1790093


2 Answers

With the help of :after - DEMO

div {
    position: relative;  
}

div:after {
  position: absolute;
  left: 0;
  top: 50%;
  height: 1px;
  background: #c00;
  content: "";
  width: 100%;
  display: block;
}
like image 152
Zoltan Toth Avatar answered Oct 20 '22 19:10

Zoltan Toth


Link To Fiddle

.wrapper {
  position:relative;
  width:110px;
}
.square {
  width:20px;
  height:20px;
  border:2px solid #000;
  display:inline-block;
  text-align:center;
}
.strike {
  position:absolute;
  width:100%;
  height:2px;
  background:black;
  top:11px;
  left:0px;
}
like image 20
Muhammad Talha Akbar Avatar answered Oct 20 '22 19:10

Muhammad Talha Akbar