我正在尝试一种更流动的设计。
我希望特定的div元素占整个页面的百分比。我还想在每个div中设置流体/液态填充。
<body>
<div class='image'></div>
<div class='fourty'></div>
<div class='sixty'></div>
</body>
CSS:
body {
margin-top: 85px;
min-height: 100%;
}
.image {
content: image_url('something.jpg');
width: 100%;
height: auto;
}
/*I'm assuming the padding I'm setting is a percentage of the .fourty
div not the overall body. Granted, width is 100%.*/
.fourty{
padding: 4% 8%;
min-height: 40%;
width: 100%;
}
.sixty{
padding: 4% 8%;
min-height: 60%;
width: 100%;
}
我遇到的问题是,这些div元素的百分比高度似乎没有生效。它似乎只是根据div内容自动调整高度。
我该如何纠正/实现呢?我可以接受JS解决方案,但更想知道如何在CSS中完成。
body
和html
的高度都设置为100%。 - Pointyvh
,它可以获取视口高度。因此,可以使用height: 100vh
。 - Lucas