css給body設定min-height為什麼沒有作用?

來源:互聯網
上載者:User
當網頁內容區content東西很少時,footer就會跑到上邊來?
我給body,html設min-height:100%;沒有作用,
設定height:100%;就好了,但是內容多了就在一屏下?

body,html{   min-height:100%;}body{   position:relative;}.content{  podding-bottom:100px;}.footer{position:absolute;bottom:0;left:0;height:100px;}

這樣寫:

html {    height: 100%;}body {    position: relative;    min-height: 100%;    box-sizing: border-box;     padding-bottom: 80px; /* .footer 的高度,為 footer 佔位 */} .footer {     position: absolute;     bottom: 0;     left: 0;     width: 100%;     height: 80px;}

上面的代碼相容到 IE8 及以上

我也遇到過這樣的問題,我就這樣解決的了:

html,body,.content{    min-height:100%;}html{    -ms-text-size-adjust: 100%;    -webkit-text-size-adjust: 100%;}body{    background:#eeeeee;}

然後用js控制讓$(".content").height($("html").height);我感覺這個調整比較可靠一點的

100%是根據他的父元素來做比較的,比如,

<div style="width:100px;">    <div style = "width:50%;"></div></div>

回到樓主的問題,所以html只能設定固定的高度,設定body高度百分比的話,那你先設定html元素的高度!

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.