【发布时间】:2012-12-01 19:22:45
【问题描述】:
Here is the HTML I am working with.
<div id="outer" style="min-width: 2000px; min-height: 1000px; background: #3e3e3e;">
<div id="inner" style="left: 1%; top: 45px; width: 50%; height: auto; position: absolute; z-index: 1;">
<div style="background: #efffef; position: absolute; height: 400px; right: 0px; left: 0px;"></div>
</div>
</div>
我希望内部 div 占据分配给其父 div(外部)的空间的 50%。相反,它获得了视口可用空间的 50%,这意味着随着浏览器/视口的尺寸缩小,它也会缩小。
鉴于外部 div 有 min-width 或 2000px,我希望内部 div 至少为 1000px 宽。
【问题讨论】:
-
内部 div 是
position: absolute,这意味着它基本上已从正常的文档流中移除,并且不再是(用于大小/位置计算)#outer 的子级。你可能想试试position: relative -
@MarcB 它不再在其父级的流程中,但您关于不是#outer 的子级的评论具有误导性。更准确的描述是它使用绝对或相对定位的第一个父/祖先进行大小/位置计算
标签: html css width css-position