【问题标题】:Prevent my Fixed Footer from overlapping content防止我的固定页脚重叠内容
【发布时间】:2019-09-17 13:16:53
【问题描述】:

我有以下代码来创建我的固定页脚:(类似于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> 

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

如何避免?

【问题讨论】:

    标签: html css position overlap


    【解决方案1】:

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

    body {
      padding-bottom: footerHeightHere
    }
    

    【讨论】:

    • 您的解决方案 + background-color 属性完成了这项工作
    猜你喜欢
    • 2011-02-14
    • 1970-01-01
    • 2017-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多