Here is the HTML I am working with。如何使div的百分比寬度相對於父div而不是視口
<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%,這意味着隨着瀏覽器/視口的大小縮小,它也是如此。
鑑於外部股利有min-width
的2000px
,我期望內部股利至少是1000px
寬。
內的div是絕對定位元素的參考' position:absolute',這意味着它基本上從正常的文檔流中被移除,並且不再(用於大小/位置計算)#outer的孩子。你可能想嘗試'position:relative' –
@MarcB它不再處於其父項流程中,但是你關於不成爲#outer子項的評論是有誤導性的。更準確的描述是,它使用絕對或相對定位的第一個父/祖輩來計算大小/位置 –