我有一个像这样的 div:
<div class="background"></div>
我试图给它 100% 的高度,这样背景颜色就是整个 div。这是我的 CSS:
html, body {
height: 100%;
}
.background {
background-color: #1D3862;
clear: both;
height: 100%;
}
但它不起作用...我该怎么做才能解决这个问题?
最佳答案
您需要从正文中删除默认边距
html, body {
height: 100%;
margin: 0;
}
html,
body {
height: 100%;
margin: 0;
}
.background {
background-color: #1D3862;
height: 100%;
}
<div class="background"></div>
关于html - CSS 背景颜色高度 100% 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30351142/