css页面布局实现,内容部分自适应屏幕,当内容高度小于浏览器窗口高度时,页脚在浏览器窗口底部;当内容高度高于浏览器窗口高度时,页脚自动被撑到窗口底部。
css如下:
<style type="text/css">
* {
???????margin: 0;
???????padding: 0;
???????box-sizing: border-box;
???}
???html,
???body {
???????width: 100%;
???????height: 100%;
???}
???.main {
???????overflow: hidden;
???????position: relative;
???????min-height: 100%;
???????background: #eee;
???}
???.red {
???????margin-bottom: 50px;
???????height: 300px;
???????background: #f00;
???}
???.footer {
???????position: absolute;
???????bottom: 0;
???????left: 0;
???????height: 50px;
???????width: 100%;
???????background: #0f0;
???}
</style>
html如下:
<div class="main">
???????<div class="red"></div>
???????<div class="footer"></div>
???</div>
通过改变red的高度,来模拟不同内容高度下,页脚的位置。
css布局-内容自适应屏幕
原文地址:https://www.cnblogs.com/wpp281154/p/9849649.html