利用flex布局实现自动高度
代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
<style type="text/css">
* {
margin: 0;
padding: 0;
list-style: none;
}
ul {
width: 200px;
height: 800px;
background-color: #ccc;
display: flex;
flex-direction: column;
}
ul>li {
width: 200px;
background-color: rosybrown;
margin-bottom: 20px;
}
ul>li:nth-child(1),
ul>li:nth-child(2) {
height: 200px;
flex-shrink: 0;
}
ul>li:nth-child(3) {
height: 100%;
}
</style>
</head>
<body>
<ul>
<li></li>
<li></li>
<li>
</li>
</ul>
</body>
</html>
效果: