我有以下代码来创建我的固定页脚:(类似于 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>
固定属性运行良好,但我没有看到我的内容的最后一行。页脚与它重叠:
如何避免?
您需要为页脚添加高度,然后添加 padding-bottom: footerHeightpx;到正文元素
body {
padding-bottom: footerHeightHere
}
我是一名优秀的程序员,十分优秀!