css布局------上下高度固定,中间高度自适应容器

论坛 期权论坛 脚本     
匿名技术用户   2020-12-30 04:09   571   0

HTML

<body>
<div class="container">
<div class="header"></div>
<div class="body"></div>
<div class="footer"></div>
</div>
</body>

CSS

body,html {
  height:100%;
}
/*方法1:绝对定位实现*/
.container {
box-sizing: border-box;
position: relative;
min-height: 100%;
padding: 100px 0;
background-color: blue;
}
.header {
position: absolute;
top: 0;
width: 100%;
height: 100px;
background-color: red;
}
.footer {
position: absolute;
bottom: 0;
width: 100%;
height: 100px;
background-color: red;
}
/*方法2:弹性布局实现*/
.container {
height: 100%;
display: flex;
flex-direction: column;
}
.body {
flex: 1 1 auto;
background-color: blue;
}
.header, .footer {
height: 100px;
flex: 0 0 auto;
background-color: red;
}

转载于:https://www.cnblogs.com/qddyh/p/10463142.html

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP