<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
*{
margin: 0;
padding: 0;
}
html,body{
height: 100%;
}
.red {
height: 200px;
background-color: rgb(151, 45, 45);
}

.green {
background-color: rgb(13, 226, 13);
height: calc(100% - 200px);
}
</style>
</head>
<body>
<div class="red">
红色
</div>
<div class="green">
绿色
</div>
</body>
</html>

[css] 剩余高度自适应_html

调整顺序,因绿色为主要内容,需要先加载

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
*{
margin: 0;
padding: 0;
}
.red {
height: 200px;
background-color: rgb(151, 45, 45);
width:200px;
position: absolute;
top: 0;
left: 0;
}

.green {
height: 200px;
background-color: rgb(13, 226, 13);
margin-left: 200px;
}
</style>
</head>

<body>
<!-- 调整顺序,因绿色为主要内容,需要先加载 -->
<div class="green">
绿色
</div>
<div class="red">
红色
</div>
</body>

</html>

[css] 剩余高度自适应_html_02