html - 防止我的固定页脚重叠内容

标签 html css position overlap

我有以下代码来创建我的固定页脚:(类似于 https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_fixed_footer)

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.footer {
   position: fixed;
   left: 0;
   bottom: 0;
   width: 100%;
   background-color: red;
   color: white;
   text-align: center;
}
</style>
</head>
<body>

<h2>Fixed/Sticky Footer Example</h2>
<p>The footer is placed at the bottom of the page.</p>
<p>The footer is placed at the bottom of the page.</p>
.....
<p>The footer is placed at the bottom of the page.</p>
<p>The footer is placed at the bottom of the page.</p>
<p>The footer is placed at the bottom of the page.</p>
<p>The footer is placed at the bottom of the page.</p>
<p>The footer is placed at the bottom of the page.</p>
<p>N-2 element</p>
<p>N-1 element</p>
<p>N element</p>

<div class="footer">
  <p>Footer</p>
</div>

</body>
</html> 

固定属性运行良好,但我没有看到我的内容的最后一行。页脚与它重叠:

enter image description here

如何避免?

最佳答案

您需要为页脚添加高度,然后添加 padding-bottom: footerHeightpx;到正文元素

body {
  padding-bottom: footerHeightHere
}

关于html - 防止我的固定页脚重叠内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57975105/

相关文章:

javascript - 全 Javascript 网页的优点

javascript - 使用一个javascript脚本动态修改另一个脚本

javascript - jquery mobile 中的点击事件

javascript - 以像素为单位查找文本区域中的插入符号位置

html - div 中的背景图像不会以绝对位置显示

javascript - HTML 单选选项文本对齐方式

html - 如何将子div设置为自动宽度父

css - 在手机上使用 rem 单位的原因?

jquery - 带有 Bootstrap 的多个下拉菜单不起作用?

jQuery UI 对话框在调用时不会关闭,但会打开