gpt4 book ai didi

css - 粘性页脚 : Why is :after needed?

转载 作者:太空宇宙 更新时间:2023-11-03 21:33:14 25 4
gpt4 key购买 nike

在下面的代码中,为什么需要 .page-wrap:after

理论上,如果没有这个,粘性页脚不应该工作吗?为什么不呢?

* {
margin: 0;
}
html, body {
height: 100%;
}
.page-wrap {
min-height: 100%;
/* equal to footer height */
margin-bottom: -142px;
}
.page-wrap:after {
content: "";
display: block;
}
.site-footer, .page-wrap:after {
height: 142px;
}
.site-footer {
background: orange;
}
<div class="page-wrap">

Content!

</div>

<footer class="site-footer">
I'm the Sticky Footer.
</footer>

最佳答案

这是为您的页脚预留空间。由于 .page-wrap 的负边距导致页脚向上拉,因此 .page-wrap 的底部需要有一个空白的“预留”空间,所以.page-wrap 中的内容不会在 .site-footer 下结束。

.page-wrap:after 就是这样做的,它在 .page-wrap 的底部添加了一个空白的“保留”空间供页脚填充。

关于css - 粘性页脚 : Why is :after needed?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28229238/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com