我有一個頁眉和sticky footer的佈局。都是40px高。現在我需要添加一個scroolbar,這將填補自由空間(verticaly)。它應該看起來像這樣:使用粘性頁腳時CSS旁邊高度100%
有兩個限制:
- 沒有JavaScript的
- 沒有CSS3計算()函數
是否有任何嚴格的CSS解決方案這個問題?
我有一個頁眉和sticky footer的佈局。都是40px高。現在我需要添加一個scroolbar,這將填補自由空間(verticaly)。它應該看起來像這樣:使用粘性頁腳時CSS旁邊高度100%
有兩個限制:
是否有任何嚴格的CSS解決方案這個問題?
以下是我即將解釋的一個小樣本:little link。
首先,分別使用absolute
和fixed
定位您的header
和footer
。將40px
填充到body
的頂部和底部,並確保其box-sizing
爲border-box
。將您的aside
的height
設置爲100%
,並確保它是border-box
。基本上;
HTML:
<header>
I'm a header!
</header>
<aside>
Lots and lots and lots of content!
Glee is awesome!
</aside>
<footer>
I'm a footer!
</footer>
CSS:
html {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
height: 100%;
}
body {
padding-top: 40px;
padding-bottom: 40px;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
height: 100%;
}
header {
height: 40px;
width: 100%;
position: absolute;
top: 0px;
}
footer {
height: 40px;
width: 100%;
position: fixed;
bottom: 0px;
}
aside {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
height: 100%;
overflow: auto; /*make sure there are scrollbars when needed*/
}
由於只有position: fixed
,利潤率(42PX進行測試的目的和原因,那麼,42,但它應該是40像素)和一個額外的div在#aside
的內部,這裏是一個小提琴:http://jsfiddle.net/PhilippeVay/xcuVv/2/,可在Firefox,Chrome,Safari 4,IE8和Opera 11或12中使用,但在IE7中失敗,並且如果需要兼容性則需要回退。
要注意的是這樣的設計並沒有考慮到:
右列會發生什麼,它是如何滾動? – FelipeAls
這是一個內容。如果內容太多,有一個問題,但高度不一定要固定。 – ciembor