Align <hr> to the left in an HTML5-compliant way

白昼怎懂夜的黑 提交于 2019-12-02 23:35:35
Stephen

You're trying to use something in a way that (as Eliezer Bernart mentions.. and apparently that comment with the link to the MDN doc disappeared) no longer "works that way". You can, as long as you don't mind it being screwy in IE, just set the margin to zero - http://jsfiddle.net/s52wb/

hr {
    max-width: 100px;
    margin: 0px;
}

A better idea though would be to mimic the HR's old way of doing things by way of CSS without the use of the HR. Check out http://jsfiddle.net/p5ax9/1/ for a demo:

p:first-child:before {
    display: none;
}
p:before {
    content: " ";
    border: 1px solid black;
    margin-top: 15px;
    margin-bottom: 15px;
    display: block;
    max-width: 100px;
}

One option would be to set the left margin to zero:

hr{max-width: 800px; margin-left:0;}

I don't know what browsers were used for some above answers, but I found neither text-align:left nor margin-left:0 worked in both IE (11, Standards mode, HTML5) and Firefox (29).

  • IE11: text-align:left works, margin-left:0 leaves rule centred.

  • FF: margin-left:0 works, text-align:left leaves rule centred.

  • So, either use both, or I found that margin-right:100% works for both!

You can use div tag instead.

<div style="border: thin solid lightgray; width: 100px;"></div>

do this

hr {
   display: inline;  //or inline-block
   text-align: left;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!