gpt4 book ai didi

html - 带有附加包装器 div 的 CSS "Sticky Footer"

转载 作者:太空宇宙 更新时间:2023-11-04 14:21:32 24 4
gpt4 key购买 nike

介绍

对于始终位于页面底部但不固定(或与内容重叠)的页脚,有许多良好且经过充分测试的方法。这是一个对我有用的:http://ryanfait.com/sticky-footer/

简而言之,它的工作原理如下:

HTML:

<html><body>
<div id="wrapper>SOME CONTENT</div><footer></footer>
</body></html>

CSS:

* {
margin: 0;
}
html, body {
height: 100%;
}
#wrapper {
min-height: 100%;
height: 100%;
margin: 0 auto -4em;
}
footer {
height: 4em;
}

诀窍是 #wrapper 被迫使用 100% 的可用高度,但 margin bottom 为页脚留出了一些空间(负边距正好是页脚的大小)。

问题描述

在构建单页应用程序时,某些 javascripts 框架(如 Ember.js)会向我们的文档结构添加额外的 div(例如,用于处理事件)。这会在我们的原始文档周围创建一个额外的包装器,它可能看起来像这样:

<html><body>
<div class="framework-container">
<div id="wrapper>SOME CONTENT</div><footer></footer>
</div>
</body></html>

这个额外的 div 破坏了我们的 CSS 设置。为了改善这种情况,我们想说 framework-container 的行为应该与 body 完全一样,因此我们可能会尝试添加:

.framework-container {
position: relative;
height: 100%;
min-height: 100%;
}

它几乎可以工作:如果内容小于页面高度。否则页脚和页面底部之间会有明显的距离 - 我们不能接受。

有人知道这个问题的纯 CSS 解决方案吗?

最佳答案

我不确定你说包装器是否有效,但你可以告诉 Ember 将应用程序插入到特定元素中,它不会在该元素之外(上方)插入任何元素。

设置根元素

App = Em.Application.create({
rootElement: '#body'
});

HTML

<div id="container">
<div id="header">I'm a header</div>
<div id="body"></div>
<div id="footer">I'm a footer</div>
</div>

CSS

html,
body {
margin:0;
padding:0;
height:100%;
}
#container {
min-height:100%;
position:relative;
}
#header {
background:#ff0;
padding:10px;
}
#body {
padding:10px;
padding-bottom:60px; /* Height of the footer */
}
#footer {
position:absolute;
bottom:0;
width:100%;
height:60px; /* Height of the footer */
background:#6cf;
}

http://emberjs.jsbin.com/OPaguRU/1/edit

我完全从中提取了一些:http://matthewjamestaylor.com/blog/keeping-footers-at-the-bottom-of-the-page

关于html - 带有附加包装器 div 的 CSS "Sticky Footer",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19893302/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com