Reputation:
div.test{width:100px;height:100px;border:1px solid red;}
The css will create a box with 100px width and 100px height .
How can draw a hr line which begins with coordinate (0,50) ,ends with coordinate(100,50) in the div.test?
Upvotes: 0
Views: 2480
Reputation: 194
What if you gave your hr a margin-top of 50%?
CSS
#line{
margin-top:50%;
}
HTML
<hr id="line" />
Upvotes: 0
Reputation: 53684
How can draw a hr line which begins with coordinate (0,50) ,ends with coordinate(100,50) in the div.test?
Use a pseudo element to draw the horizontal line absolutely positioned relative to the parent.
div.test {
width: 100px;
height: 100px;
border: 1px solid red;
position: relative;
}
.test::after {
content: '';
border: 1px solid black;
position: absolute;
top: 50%;
left: 0;
right: 0;
}
<div class="test"></div>
Upvotes: 3
Reputation: 3730
Position the <hr>
accordingly.
div.test{width:100px;height:100px;border:1px solid red;}
hr {
position: relative;
z-index: -1;
margin-top: -50px;
width: 100px;
margin-left: 0px;
}
<div class="test"></div>
<hr>
Upvotes: 0