1

我有一个<hr>需要为其父级宽度的 80% 和“左对齐”,而不是默认居中。

<div>
    <p>Some stupid text</p>
    <hr>
    <p>Ask a stupid text, what?</p>
</div>

我通过使用以下方法在现代浏览器中解决了这个问题:

hr
{
    width: 80%;
    color: #90b124;
    background: #90b124;
    height: 4px;
    border: 0;
    margin: 20px 0;
    position: relative;
    left: 0;
}

但在 IE(所有版本)中,它仍然居中。设计要求这个左侧定位的小时。当然,我可以只使用 a<span>并称其为一天,但这不那么语义化。

有没有办法在 IE 中将其定位为 deisred ?

http://jsfiddle.net/jWcEp/

4

2 回答 2

3

我知道@Nicsoft 的答案对你有用,但还有另一种方法。

<hr>曾经有一个align属性,在 HTML5 中不支持。这已被text-alignIE 和 Opera 以及margin-left/rightFirefox 和 WebKit 的 CSS 属性所取代。所以要左对齐,你可以这样做:

hr {
    margin-left:0
    text-align:left;
    width:80%;
}

如此处所见并此处描述。

于 2012-12-18T10:37:58.683 回答
1

将 float:left 添加到 hr{}

hr
{
    float:left; //Makes the element float to he left
    width: 80%;
    color: #90b124;
    background: #90b124;
    height: 4px;
    border: 0;
    margin: 20px 0;
    position: relative;
    left: 0;
}

不要忘记适当地清除。

于 2012-12-18T10:30:11.570 回答