简体   繁体   中英

CSS background doesn't stretch to the full height

I have an element with 100% height. If there are a lot of blocks, then they go beyond it.

jsfiddle example: http://jsfiddle.net/yPqKa/

How to fix it?

Thanks in advance.

CSS:

html, body {
    height: 100%;
    width: 100%;
}
.content-background {
    background-color: #000;
    height: 100%;
    width: 100%;
}
.content {
    background-color: #eee;
    height: 50px;
    width: 100%;
    margin-top: 60px;
}

Set a min-height on the body :

html {
    height: 100%;
    width: 100%;
}
body{
    min-height:100%;
}

DEMO

This will allow the body to adapt it's height to the overflowing content.

The problem is that you have set the height of the html and body elements to 100% of their container, which restricts them to be smaller than the elements they contain. If you remove the height: 100%; from the second line, it will work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM