Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make <hr> full width?

Tags:

html

css

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.

like image 482
user3187469 Avatar asked Feb 20 '14 23:02

user3187469


People also ask

How do you make a HR line full width?

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 /> .

How can I make my HR width 100%?

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.

How do I change the width of my HR?

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.

How do you set full width?

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.


2 Answers

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

like image 125
Code Maverick Avatar answered Oct 12 '22 12:10

Code Maverick


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

like image 25
Alistair Chisholm Avatar answered Oct 12 '22 14:10

Alistair Chisholm