我有一個頁眉,內容和頁腳的網頁。如何讓div填充剩餘空間?
內容中有背景圖片。我希望圖像填充頁眉和頁腳之間的剩餘空間。有div的內容div的孩子與圖像,有時會有內容和其他時間不會。
HTML:
<body>
<div id='main'>
<div id='header'>
<div id='logoCompany'>
<img class='headerGraphics' src='Graphics\logo smaller.jpg'><img class='headerGraphics' src='Graphics\Marvelous Header3 small.png'>
</div>
</div>
<div id='contentParent' class='floatClear'>
<div id='content' style = "text-align: center;">
<div id='leftPane'>
Left Col
</div>
<div id='rightPane'>
Right Col
</div>
</div>
</div>
<div id='footer'>
Footer
</div>
</div>
</body>
CSS:
* {
margin: 0px;
}
.floatClear {
clear: both;
}
.headerGraphics {
display: inline;
}
#header {
background: #023489;
text-align: center;
}
#logoCompany {
display: inline;
}
#contentParent {
height: 373px;
width: 100%;
background-image: url(../Graphics/background.jpg);
}
#leftPane {
background: yellow;
float: left;
margin: 100px 0 0 10%;
opacity: .5;
width:40%;
}
#rightPane {
background: green;
float: right;
margin: 100px 10% 0 0;
opacity: .5;
width:40%;
}
#footer {
width:100%;
}
我試過高度:100%,但我懷疑這會失敗,且不內容。事實上,我認爲這就是爲什麼一切都失敗,除非我硬編碼一個高度。但由於明顯的原因,這不是一個好的解決方案。
任何人有任何想法如何使這項工作?
編輯: 我試圖改變這樣的:
#contentParent {
height: 373px;
width: 100%;
background-image: url(../Graphics/background.jpg);
}
這樣:
#contentParent {
flex: 1;
background-image: url(../Graphics/background.jpg);
}
但縮水DIV孩子div的尺寸,使事情變得更糟..
的Flex並沒有爲我工作。 – Fred
在片段上完美工作。最新的問題是什麼? – dippas