div上中下布局中间自适应
2024-09-02 16:37:44
需求1: 头尾固定高度,中间自适应
1.上部(header)Div高度固定100px,宽度100%;
2.下部(footer)Div高度固定100px,宽度100%;
3.中部(middle)DIV高度根据屏幕高度,自适应充满(是根据内容自动填满),宽度100%;
4.用纯DIV+CSS实现,不采用脚本计算高度的方式;
5.调整浏览器大小时,中部DIV能随着屏幕高度自适应。
CSS部分
<style type="text/css">
*{
margin:;
padding:;
text-align: center;
}
.container{ background: #fff;
margin: 0 auto;
text-align: left;
}
.header{
padding: 10px 0;
background: pink;
}
.middle{
padding: 10px 0;
}
.footer{
padding: 0px;
background:pink;
} </style>
HTML部分
<div class="container">
<div class="header">
<p>heder</p>
</div>
<div class="middle">
<p>content</p>
<p>content</p>
<p>content</p>
<p>content</p>
<p>content</p>
<p>content</p>
</div>
<div class="footer">
<p>footer</p>
</div>
</div>
需求2:头部固定,中间和底部设置为绝对定位,
*{
margin:;
padding:;
}
.container{
text-align: center;
font-size: 30px;
}
.header,.footer{
width: 100%;
height: 200px;
line-height: 100px;
background-color: red;
}
.middle{
width: 100%;
position: absolute;
top: 100px;
bottom:100px;
background-color: yellow;
}
.footer{
position: absolute;
bottom: 0px;
}
最新文章
- BZOJ 4614 【Wf2016】 Oil
- Android 学习第17课,使用文件的数据存储(4种存储模式)
- unity3d5.2.3中 调整视角
- Visual Studio 2013智能提示失效解决办法
- [Unity菜鸟] 协程Coroutine
- Github是什么?看完你就了解一些了
- JavaScript设计模式之----组合模式
- 为什么要使用CMake?
- js实现获取当前时间是本月第几周和年的第几周的方法
- cent6.x配置主机名及静态网络
- 第三章:Activity的生命周期
- Kotlin入门(17)等式判断的情况
- [UE4]嵌套Canvas
- 通过这些示例快速学习Java lambda语法
- 管理KVM虚拟机(二)
- 使用Ocelot构建GateWay
- Sqlite 常用函数推荐
- ASLR
- hdu4347
- webshell三剑客[aspxspy、phpspy、jspspy]