页脚内容与媒体查询重叠

  • 本文关键字:媒体 查询 重叠 html css
  • 更新时间 :
  • 英文 :


我有一个简单的页脚,我希望它始终位于页面底部。

目前,它固定在页面底部,但是当页面内容较高并且需要滚动时,页脚位于代码顶部,而不是底部。

.footer {
position: fixed;
bottom: 0;
width: 100%;
height: 8vh;
background-color: #000000;
}
@media only screen and (max-width: 500px) {
.footer {
position: fixed;
bottom: 0;
width: 100%;
height: 16vh;
background-color: #000000;
}
<div class="footer">
</div>

指针真的会受到赞赏,底部没有空白。我试过粘性,但也没有用。

提前谢谢。

如果您希望页脚保持固定(始终可见(到页面底部,则可以为页脚提供与页脚高度相等的填充<body>。这样,任何内容都不会隐藏在页脚后面。

我从这里学到了一种方法,这可能会对你有所帮助。只需要按如下方式构建您的 HTML:

<div id="container">
<div id="header"></div>
<div id="body"></div>
<div id="footer"></div>
</div>

并像这样声明您的样式:

html,
body {
margin:0;
padding:0;
height:100%;
}
#container {
min-height:100%;
position:relative;
}
#header {
background:#ff0;
padding:10px;
}
#body {
padding:10px;
padding-bottom:60px;   /* Height of the footer */
}
#footer {
position:absolute;
bottom:0;
width:100%;
height:60px;   /* Height of the footer */
background:#6cf;
}

它对我有用,希望对您也有帮助。

最新更新