【发布时间】:2016-09-02 10:13:44
【问题描述】:
以下脚本(https://jsfiddle.net/u9z76r6q/2/) 不在 IE-11 中居中:
.container {
display: block;
width: 400px;
height: 200px;
text-align: center;
border: 1px solid black;
}
span {
position: absolute;
}
<a href="#" class="container">
<span>
<img src="https://redarrowmedia.files.wordpress.com/2012/03/arrow-logo1.png" alt="" width="40px" height="40px">
</span>
</a>
在所有其他现代浏览器中,箭头图像居中。这是 Internet Explorer 中的错误吗?
【问题讨论】:
-
在我看来 Chrome/FF 和 IE 是错误的。 IE 的行为就像将
left设置为0和 Chrome/FF 一样,就好像元素没有宽度一样。老实说,我在规范中找不到关于text-align: center和left: auto组合的信息,但在CSS absolute and fixed positioning 中的描述之外,我会说IE 肯定是错误的,Chrome/FF 稍微有点。 -
很有趣,曾经只有 IE 以这种方式表现......其他浏览器不介意文本对齐......我不明白为什么他们应该将元素排除在流之外。很久以前,我养成了重新定义左坐标以在任何地方都有相同行为的习惯。就像 CSS 中的任何其他安全重置一样
-
@GCyrillus 其他浏览器应该注意文本对齐,因为这里
left是auto。
标签: html css internet-explorer css-position internet-explorer-11