【发布时间】:2013-01-13 01:25:31
【问题描述】:
喂!
我对 webkit-browsers 和 firefox 中某些元素的定位有疑问。
在 Safari/Chrome 中,我希望它是这样的:
但在 Firefox 中,它看起来像这样:
代码
HTML
<ul>
<li>
<div class="img">
<a href="#">
<img src="#" />
<p><span class="circle"><img src="white-circle.png" alt="" /></span></p>
</a>
</div>
</li>
</ul>
CSS
li {
position: relative;
}
p {
top: 0;
width: 100%;
height: 100%;
position: absolute;
text-align: center;
background-color: black;
}
p img {
width: 70%;
height: 70%;
position: absolute;
top: 50%;
left: 50%;
margin-top: -35%;
margin-left: -35%;
}
知道那里发生了什么吗? Firefox 对 position: absolute 的解释是否不同?
【问题讨论】:
-
我已经在 Firefox 中测试过它也可以工作。
-
不想在这里粗鲁或冒犯所以不要误解,但是这个 html 有点恐怖,空的图像标签?图像周围的 p 和跨度?为什么一个 div 包裹着它 为什么你不给 li 上课?一切正常,难怪浏览器不能正确呈现它
-
@LeventeNagy 当然你是对的,但请记住这只是一个例子。我可能过于简单化了,是的。
标签: html css positioning css-position