主要是需要留意 flex布局和overflow 之间的关系,
最外面的container 和 里面的main-box 之间分别使用了flex布局 和 overflow:hidden main-box 和 里面的main-body 之间分别使用了 flex布局 和 overflow:auto 有点类似于聊天的窗口布局
<! 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>
body {
margin : 0;
}
.container {
width : 800px;
height : 600px;
margin : auto;
background-color : #bfa;
display : flex;
flex-direction : column;
}
.container-title {
border : 3px solid red;
height : 40px;
}
.main-box {
flex : 1;
overflow : hidden;
border : 3px solid blue;
display : flex;
flex-direction : column;
}
.main-header {
height : 80px;
border : 3px solid pink;
flex-shrink : 0;
}
.main-body {
border : 3px solid pink;
flex : 1 1 auto;
overflow-y : auto;
}
.main-body-long-content {
height : 600px;
}
.main-footer {
height : 80px;
border : 3px solid pink;
flex-shrink : 0;
}
</ style>
</ head>
< body>
< div class = " container" >
< div class = " container-title" > 容器标题 - 高40px</ div>
< div class = " main-box" >
< div class = " main-header" >
我是标题 - 80px
</ div>
< div class = " main-body" >
< div class = " main-body-long-content" >
很的长内容...
(这里可以用el-scrollbar)
</ div>
</ div>
< div class = " main-footer" >
我是尾部 - 80px
</ div>
</ div>
</ div>
</ body>
</ html>