<分区>
<分区>
我知道这个问题之前已经被问过很多次了,但我似乎没有把我的例子说对。如何让紫色的 div 填充窗口的剩余高度?
<!DOCTYPE html>
<html>
<head>
<style>
body {
height: 100%;
margin: 0;
}
.container {
display: flex;
flex-flow: column;
height: 100%;
}
.topbox {
background-color: red;
flex: 0 1 40px;
}
.bottombox {
background-color: purple;
flex: 1 1 auto;
}
</style>
</head>
<body>
<div class="container">
<div class="topbox"></div>
<div class="bottombox"></div>
</div>
</body>
</html>
最佳答案
在 html 标签上添加 100% 高度。
html {
height: 100%;
}
<!DOCTYPE html>
<html>
<head>
<style>
html {
height: 100%;
}
body {
height: 100%;
margin: 0;
}
.container {
display: flex;
flex-flow: column;
height: 100%;
}
.topbox {
background-color: red;
flex: 0 1 40px;
}
.bottombox {
background-color: purple;
flex: 1 1 auto;
}
</style>
</head>
<body>
<div class="container">
<div class="topbox"></div>
<div class="bottombox"></div>
</div>
</body>
</html>
关于html - 填充窗口的剩余高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50678664/