1.flex布局有时候overflow: auto不生效,解决办法如下
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>flex布局</title>
<style>
html,
body {
margin: 0;
width: 100%;
height: 100%;
}
.body {
display: flex;
flex-direction: column;
width: 100%;
height: 100%;
/* background: #099; */
}
.top {
height: 200px;
border: 3px solid #090;
}
.center {
flex: 1;
/* 这块一定要加,不然没有滚动条 */
overflow: auto;
/* overflow: hidden; */
border: 3px solid #f00;
}
.center-body {
height: 2000px;
}
.bottom {
height: 100px;
border: 3px solid #090;
}
/* 2 */
.center2 {
display: flex;
flex: 1;
flex-direction: column;
overflow: hidden;
/* overflow: auto; */
border: 3px solid #f00;
}
.center2-top {
height: 30px;
background: #099;
}
.center2-center {
flex: 1;
overflow: auto;
}
.center2-bottom {
height: 30px;
background: #099;
}
.center-body2 {
height: 2000px;
}
</style>
</head>
<body>
<div class="body">
<div class="top">
top
</div>
<div class="center">
<div class="center-body">
center
</div>
</div>
<!-- 2 -->
<div class="center2">
<div class="center2-top">center2-top</div>
<div class="center2-center">
<div class="center-body2">
center2-center
</div>
</div>
<div class="center2-bottom">center2-bottom</div>
</div>
<div class="bottom">
bottom
</div>
</div>
</body>
</html>