我在我的容器div上使用min-height: 200vw
和position: relative
,我使用position: absolute
和bottom: 0
在其中有一个页脚。如何防止内容在页脚下方,并使页脚向下推?
.container {
position: relative;
min-height: 200vh;
width: 100%;
}
.content-text {
font-size: 2em;
}
footer {
width: 100%;
height: 10em;
position: absolute;
bottom: 0;
background: red;
opacity: .5;
}

<div class="container">
<p class="content-text">Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main </p>
<footer>
<p>Footer Content</p>
</footer>
</div>
&#13;
答案 0 :(得分:3)
根据您的代码,一种简单的方法是为容器提供与padding-bottom
的高度等效的footer
。
.container {
position: relative;
min-height: 200vh;
width: 100%;
/* added */
padding-bottom: 10em;
}
.content-text {
font-size: 2em;
}
footer {
width: 100%;
height: 10em;
position: absolute;
bottom: 0;
background: red;
opacity: .5;
}
&#13;
<div class="container">
<p class="content-text">Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content...
Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content...
Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content...
Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content...
Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content...
Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content...
Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content... Main content...
Main content... Main content... Main content... Main content... Main content... Main content... Main </p>
<footer>
<p>Footer Content</p>
</footer>
</div>
&#13;