Home > Web Front-end > CSS Tutorial > Why does css setting min-height to body have no effect?

Why does css setting min-height to body have no effect?

黄舟
Release: 2017-07-21 09:53:06
Original
4102 people have browsed it

When there is very little content in the content area of ​​the web page, the footer will come to the top?
I set min-height: 100%; for body and html, it has no effect.
Setting height: 100%; is fine, but if there is too much content, it will fit on one screen?

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

Write like this:

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;
}
Copy after login

The above code is compatible with IE8 and above

I have also encountered such a problem, and I solved it like this:

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

Then use js control to make $(".content").height($("html").height); I feel that this adjustment is more reliable

100% based on its parent Elements are used for comparison. For example,

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

Back to the original poster’s question, so html can only set a fixed height. If you want to set the body height percentage, then you set the height of the html element first!

The above is the detailed content of Why does css setting min-height to body have no effect?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template