【发布时间】:2022-11-23 17:23:54
【问题描述】:
我正在做一个项目,我试图让页脚留在页面底部,但在您滚动到页面底部之前看不见。我尝试在我的 CSS 中使用“位置:固定”,但它漂浮在我的内容上方,因为它绝对停留在页面中间并覆盖了内容。另外,对于没有太多内容的页面,当我没有指定位置或使用“position: absolute”时,页脚下方会有空白。请提供建议。
* {
margin: 0;
padding: 0;
}
header {
background-color: gray;
}
footer {
background-color: gray;
bottom: 0;
height: 20px;
position: fixed;
width: 100%;
}
/* when I use the fixed position, the footer is fixed above my content. What I want is for the footer to remain at the bottom of the page but out of sight. */
<html>
<body>
<header>Heading</header>
<main>
<h1>Heading</h1>
<p>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Adipisci eos deserunt fugiat doloremque your text`ut.</p>
</main>
<footer>© Copyright, Business</footer>
</body>
</html>
【问题讨论】:
-
你好,我不太明白。您是否希望页脚始终在屏幕上可见?如果不是,则页面末尾的页脚,滚动时,在您看到页脚的位置。但是,如果在页面顶部的页脚不可见,对吗?
-
如果您希望它保留在页面底部,如果它是页面上的最后一项,那不是默认情况下它已经做的事情。也许你应该改写你的问题
-
是的,这是正确的@pierfarrugia
-
@Joshua 正如我在问题中所说,对于内容较少的页面,页脚不会留在底部。它下面有空间。