http://jsfiddle.net/bh2f6/1/
I want to make this <hr/>
so it will stretch the full width, right to the edges of its parent container. I have tried adding margin-left/padding-right to overcome this but it keeps changing when resizing (responsive).
Is there a better solution for this?
Edit: I can't edit the parent container's padding as that is needed for bunch of other elements.
Your width:100%; on the <hr /> and the padding on the parent were messing things up. The <hr /> naturally stretches across the screen and doesn't need width:100% , so remove it. Then to compensate for the padding, just add the same negative margin to the <hr /> .
Setting the border width to 0 will fix this. Show activity on this post. Also note for older browsers you will need to set font-size: 0 and line-height: 0 to remove any default height given to the <hr> element.
Change the size and position of a horizontal rule The <hr> element is styled with CSS rules instead of attributes. Change the width of the horizontal line by setting the width property and then center it using the margin property.
What you could do is set your div to be position: absolute so your div is independent of the rest of the layout. Then say width: 100% to have it fill the screen width. Now just use margin-left: 30px (or whatever px you need) and you should be done.
Your width:100%;
on the <hr />
and the padding
on the parent were messing things up. The <hr />
naturally stretches across the screen and doesn't need width:100%
, so remove it. Then to compensate for the padding, just add the same negative margin to the <hr />
.
Change your CSS to this:
.single-article hr {
margin: 30px -20px 20px;
border: 0;
border-top: 1px solid #c9c7c7;
}
See working jsFiddle demo
Something like this might work...
hr {
padding: 50px 0;
border: none;
&:before {
// full-width divider
content: "";
display: block;
position: absolute;
right: 0;
max-width: 100%;
width: 100%;
border: 1px solid grey;
}
}
http://codepen.io/achisholm/pen/ZWNwmG
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With