好吧,我有一個容器div包含兩個左右浮動的div。這些子div的高度取決於裏面的內容(目前只是文本)。CSS div不改變高度以適合較大的孩子div
問題是容器div的高度沒有正確變化以適合孩子;它只適合右手格子,並不適合左手。
我已將所有div的高度設置爲auto。我也嘗試將較大的小孩div的大小設置爲100%,但似乎沒有效果。
下面列出了CSS的三個相關部分(我還會給出一個鏈接到網站,以便在需要時可以檢查CSS和HTML的其餘部分)。
#container{
/*
The container, contains the page and the footer
*/
height: auto; /* this is the problem child...*/
width: 1000px;
margin: auto;
padding-top: 20px;
background-color: white;
}
#content{
/*
The container, contains the content of the webpage
*/
height: auto;
width: 600px;
margin: 10px 10px 0px 10px;
background-color: white;
float: left;
}
#aside{
/*
The aside to be used for additional information
*/
height: auto;
width: 330px;
float: right;
margin: 10px 10px 0px 10px;
padding: 5px 15px 5px;
background-color: #E8E8E8;
border-radius: 25px;
}
基本上我想它使容器將是兩個孩子的身高合適的高度(但在這種情況下,它永遠是右手一個我認爲)。但目前它似乎總是匹配較小的一個。
鏈接到可以看到的網站:http://timbrodrick.com/aboutWebsite.html 「©2014 Tim Brodrick,[email protected]」是頁腳的一部分,它是從容器div開始的div的一部分。
這就是浮動元素髮生的情況 - 它們不影響父母的身高。通過搜索關鍵字「clearfix」可以找到與這種行爲相對應的技術。 – CBroe