我具有以下代码来创建固定的页脚:(类似于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>
固定属性的效果很好,但是我看不到竞争的最后一行。页脚与之重叠:
如何避免呢?
答案 0 :(得分:1)
您需要在页脚中添加高度,然后在底部添加填充:footerHeightpx;到身体元素
body {
padding-bottom: footerHeightHere
}