html - CSS - div 的高度为零但已经设置了高度

标签 html css background

我目前正在开发一个网站。我想要一个具有以下属性的背景 div:

#background {
    background-image: url("../images/background.png");
    width: 100%;
    height: 100%;
    background-position: center;
    z-index: 1;
}

我的 div 基本上是 <div id="background"></div> .

但是在我的网站中,背景 div 显示的高度为 0。有什么办法可以解决吗?

最佳答案

Demo

CSS

body, html {
    height: 100% /* give height to your body and html */
}

关于html - CSS - div 的高度为零但已经设置了高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24301060/

相关文章:

html - 修复了背景封面上的文字

javascript - 如何避免 Angular 中的元素重叠

html - 如何取消子 div 的不透明度?

javascript - 将复选框更改为选中单击跨度不起作用

Android ListView 状态列表不显示默认项目背景

ios - 使用关闭的相机快门作为 View 背景

javascript - 将文本标签和/或图标附加到 div

javascript - 如何防止我的页面重新加载? (我在 HTML 中,我做了建议的方法,但它没有用)

iphone - 显示xml页面的内容

css - 根据 ContentPlaceHolder 的大小增加 wrapper 的高度