3 回答
TA贡献1775条经验 获得超11个赞
100%
min-height
100%
#footer { clear: both; position: relative; height: 200px; margin-top: -200px;}
TA贡献1869条经验 获得超4个赞
视图演示
::after
body
absolute
基本通用标记
html{ height:100%; }
body{ min-height:100%; padding:0; margin:0; position:relative; }
header{ height:50px; background:lightcyan; }
footer{ background:PapayaWhip; }
/* Trick: */
body {
position: relative;
}
body::after {
content: '';
display: block;
height: 50px; /* Set same as footer's height */
}
footer {
position: absolute;
bottom: 0;
width: 100%;
height: 50px;
}
<body>
<header>Header</header>
<article>Content</article>
<footer>Footer</footer>
</body>
下面的方法允许动态页脚高度:
使用挠曲箱
html, body{ height:100%; margin:0; }
header{ height:50px; background:lightcyan; }
footer{ height:50px; background:PapayaWhip; }
/* Trick */
body{
display:flex;
flex-direction:column;
}
footer{
margin-top:auto;
}
<body>
<header>Header</header>
<article>Content</article>
<footer>Footer</footer>
</body>
使用表-布局
html,body { height: 100%; margin: 0; }
header {
height: 50px;
background: lightcyan;
}
footer {
height: 50px;
background: PapayaWhip;
}
/**** Trick: ****/
body {
display: table;
width: 100%;
}
footer {
display: table-row;
}
<body>
<header>Header</header>
<article>Content</article>
<footer>Footer</footer>
</body>
- 3 回答
- 0 关注
- 949 浏览
相关问题推荐
添加回答
举报