首页 > web前端 > css教程 > 正文

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

黄舟
发布: 2017-07-21 09:53:06
原创
4036 人浏览过

当网页内容区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中文网其他相关文章!

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!