粘连布局,又称为stick footer布局
如果页面内容不够长的时候,页脚块粘贴在视窗底部;如果内容足够长时,页脚块会被内容向下推送。
image.png
image.png
总结
- footer必须是一个独立的结构,与wrap没有任何嵌套关系
- footer要使用margin为负来确定自己的位置
- wrap区域必须要被自己的子元素撑开
- 如果真的想在wrap区域外添加其他结构,这个结构必须定位
实现代码
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<title></title>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
html,body{
height: 100%;
}
#wrap{
min-height: 100%;
}
#footer{
height: 50px;
background: pink;
line-height: 50px;
text-align: center;
margin-top: -50px;
}
#main{
text-align: center;
padding-bottom: 50px;
}
</style>
</head>
<body>
<div id="wrap">
<div id="main">
n <br/>
n <br/>
</div>
</div>
<div id="footer">footer</div>
</body>
</html>