【发布时间】:2015-09-25 11:12:16
【问题描述】:
我尝试为每个页面创建一个页脚。目标是使页脚居中并将其放置在页面底部。可以查看我的JSFiddle,或者直接看代码如下。
HTML
<div id="page1" class="page">
<div class="footer">
<p>1</p>
</div>
</div>
CSS
div.page {
height: 300px;
width: 180px;
border: 1px solid #000;
margin: auto;
margin-bottom: 5px;
text-align: center;
}
div.footer {
background-color: #DDD;
width: 100%;
bottom: 0; /* doesn't work */
}
p {
width: 15px;
color: white;
background-color: red;
text-align: center;
margin: auto;
bottom: 0;
}
我看到了关于How to position div at the bottom of a page ? 的类似问题。但是,当我应用它的提议时,bottom + position 设置,每个页面中的页脚都合并在一起,放置在导航器窗口的底部。这是相关的JSFiddle
有人可以帮忙吗?非常感谢。
【问题讨论】:
-
查看我的回答,希望对您有所帮助。
-
你需要将
position:relative添加到页面div和position:absolute到页脚div -
@AlessandroIncarnati 无需评论只是说您已经创建了答案。提问者会自动收到通知(向下滚动并自己弄清楚并不难!)。
-
@Sverri M. Olsen 有时我发现如果用户没有立即回复以向他们发送附加通知,这很有用。无论如何,感谢您指出这一点。 :) 很高兴回答。
-
@AlessandroIncarnati 如果他们没有响应第一个通知,那么第二个通知不会有任何影响。这不是人气竞赛。只需添加您的答案,让人们在闲暇时进行评估和回应。