简体   繁体   English

CSS背景无法达到最大高度

[英]CSS background doesn't stretch to the full height

I have an element with 100% height. 我有一个高度为100%的元素。 If there are a lot of blocks, then they go beyond it. 如果有很多障碍,那么它们就会超越障碍。

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

How to fix it? 如何解决?

Thanks in advance. 提前致谢。

CSS: 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 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. 问题是您已将html和body元素的高度设置为其容器的100%,这限制了它们小于它们所包含的元素。 If you remove the height: 100%; 如果除去height: 100%; from the second line, it will work. 从第二行开始,它将起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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