首页  >  文章  >  web前端  >  css给body设置min-height为什么没有作用?

css给body设置min-height为什么没有作用?

黄舟
黄舟原创
2017-07-21 09:53:064007浏览

当网页内容区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元素的高度!

以上是css给body设置min-height为什么没有作用?的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn