我在理解div中元素高度的問題。我有一個標題div,裏面有一些div。div裏面佔有一定的高度。當頭部未被提及時,頭部是否應該覆蓋由其內部定義的元素佔據的區域。根據我的理解,頭文件應該將所有的div包裹在裏面。元素在css中的高度
如果我錯了,請糾正我。
這是我的身體
<div style=" float:left; background-color:pink; width:20%; height:40px; ">
THis is left
</div>
<div style=" float:left; background-color:gray; width:70%; height:40px; " >
<div id="htop">
This is top
</div>
<div id="hbutt" >
this is buttom
</div>
</div>
而且這裏去風格
#cont{ background-color:yellow; width:900px; height:300px; margin:auto; padding:40px; }
#header{ background-color:red; width:100%; padding:5px; }
#cont2{ background-color:blue; width:10%; height:auto; padding:5px; clear:both; }
#htop{ background-color:maroon; }
#hbutt{ background-color:purple; }
對於輸出和可能的變化需要https://jsfiddle.net/sum1/vmq3y2rv/
http://stackoverflow.com/questions/16568272/how-does-css-float-work-why-doesnt-the-height-of-a-container-element-increase – 2015-02-23 06:14:22