這裏是我的HTML:如何在高度可變時將兩個元素合併爲一個?
.parent{
position: fixed;
border: 1px solid;
height: 43%;
width: 300px;
}
.first_el{
display:block;
border: 1px solid green;
height: 30px; /* constant */
}
.second_el{
border: 1px solild red;
height: 100%; /* dynamic */
overflow: scroll;
}
<div class="parent">
<span class="first_el">title</span>
<div class="second_el">
one<br>two<br> three<br> four<br> five<br> six<br> seven<br> eight<br>nine<br>
</div>
</div>
正如你所看到的,第二個元素是從它的父。問題是,如何將所有屏幕尺寸設置爲其父級?
注意到我可以使用calc(100%-30px)
作爲height
的.second_el
然後問題就解決了。但正如我所知calc
舊版瀏覽器不支持calc()
,因此我不想使用它。有其他選擇嗎? (因爲舊瀏覽器,我也不想使用box-sizing: border-box;
)
如果你真的想支持古代瀏覽器,那麼你意識到'position:fixed'也不在話下吧?順便說一句,你在'.second-el'的邊框樣式中有一個錯字。 –