【发布时间】:2018-05-27 08:16:13
【问题描述】:
我找不到此问题的解决方案。我想要一个始终位于底部(不粘/固定)的页脚,以及始终位于底部(不粘/固定)的背景。
为了更清楚我做了一张图:https://i.imgur.com/qVLb1bl.png
<html>
<div id="container">
<div class="content">
<h1>Content</h1>
</div>
<div class="footer">
<h2>Footer</h2>
</div>
</div>
</html>
CSS:
html, body { height: 100%; }
body { display: flex; flex-direction: column; background: url('http://www.freetoursbyfoot.com/wp-content/uploads/2013/08/New-York-Skyline-Downdown-view.jpg') no-repeat bottom center; }
#container { display: flex; flex-direction: column; height: 100%; }
.content { max-width: 800px; width: 100%; height: 400px; margin: 0 auto; background: #eee; margin-top: 20px; text-align: center; padding-top: 30px; }
.footer { max-width: 800px; width: 100%; height: 100px; background: #000; margin: auto auto 0 auto; }
我还做了一个codepen:https://codepen.io/nickm10/pen/XVJjGb
有人知道解决办法吗?
谢谢!
【问题讨论】:
-
.footer { position:absolute; top: 100%; bottom: 0; left: 0; right: 0; margin: 0 auto; text-align: center; max-width: 800px; width: 100%; height: 100px; background: #000; },也将页脚标签放在container div之外,必须添加top: 100%
标签: html css background footer