我正在嘗試製作帶有固定標題和可滾動內容區域的網頁。當標題有一個已知的高度時,這是微不足道的,但我正努力尋找一個解決方案,以確定標題是否流暢。如何使用CSS定位固定可變高度標題和可滾動內容框?
我想要的佈局是:
--------------
head
--------------
content
--------------
其中「頭」是它的任何高度的內容需要它是和「內容」沒有最低高度,但將達到視口底部的最大高度在成爲可滾動之前。
這些日子在純CSS中可能嗎?我針對的是IE8 +。
爲了澄清我想要什麼,here is what I would do if I knew the height of the header:
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body {
margin: 0;
}
#head {
background: yellow;
height: 20px; /* I can't rely on knowing this. */
}
#content {
background: red;
position: absolute;
top: 20px; /* here also */
bottom: 0;
width: 100%;
overflow: auto;
}
</style>
</head>
<body>
<div id="head">some variable height content</div>
<div id="content">
scrollable content<br/>
scrollable content<br/>
scrollable content<br/>
scrollable content<br/>
scrollable content<br/>
scrollable content<br/>
scrollable content<br/>
scrollable content<br/>
scrollable content<br/>
scrollable content<br/>
scrollable content<br/>
scrollable content<br/>
scrollable content<br/>
scrollable content<br/>
scrollable content<br/>
</div>
</body>
</html>
您是否希望將滾動條放在內容的旁邊或整個頁面的高度? – Eric
如果標題是「固定的」,它的高度是多少? – Eric
滾動條理想地位於內容的旁邊。當我說固定的時候,我的意思是位置,即。它不會隨主要內容一起滾動。 –