当属性使用calc时,里面可以使用100%或vh(当前可视区域100%高度),该属性值会动态计算并修改
<!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>
html,body {
height: 100%;
}
body {
margin: 0;
display: flex;
}
.box1 {
height: calc(100% - 200px);
background-color: #bfa;
width:20%;
}
.box2 {
height: calc(100vh - 200px);
background-color: pink;
width:20%;
}
.box3 {
height: calc(100vh - 200px);
background-color: coral;
width:20%;
}
.box4 {
width: 100px;
height: 100px;
background-color: grey;
}
</style>
</head>
<body>
<div class="box1"></div>
<div class="box2"></div>
<div class="box3"></div>
<div class="box4"></div>
</body>
</html>