【发布时间】:2016-10-08 23:43:20
【问题描述】:
我在 Google Chrome 中的相对定位有问题 以下代码在 IE 中运行良好,但在 Chrome 中运行不正常。 相对定位是相对于元素的正常位置。 红框的正常位置在黑框的正下方。 如果我添加 10% 的空间,红色框应该会出现在正常位置下方 10% 处。
HTML
<body>
<div id="outer">
<div id="inner1">
</div>
<div id="inner2">
</div>
</div>
</body
CSS
#outer
{
position:absolute;
left:20%;
right:20%;
bottom:20%;
top:20%;
background-color:Blue;
}
#inner1
{
position:relative;
width:20%;
height:20%;
background-color:Black;
}
#inner2
{
position:relative;
top:10%;
width:20%;
height:20%;
background-color:Red;
}
【问题讨论】:
-
父元素需要
Width- 和height,因此您可以使用%中的宽度。 解决方案 1) - 给父元素一个宽度和高度。 解决方案 2) - 给红框一个margin-top:__px -
你到底是什么样子的?因为在我看来还可以jsfiddle.net/WrKk9
-
在 Firefox 中运行时真的很烦人 = =
-
@man 这是因为在 op 的情况下,维度是通过指定顶部和底部来指定的。如果它是只有顶部和自动高度的普通父级,则会出现问题。
标签: html css positioning