在较低的 div 中带有 bg 图像的 HTML CSS 布局

标签 html css layout footer

我怎样才能让 div 'lower' 用它的背景图像填充屏幕的下部?

Div 'upper' 根据内容增长。

红线标记视口(viewport)。

这里我有一个例子,我是如何用一个表来做的:Splendid

但我想要它无表!!

enter image description here

最佳答案

警告:这个回答并没有解决原来的问题,我误解了他的问题。作者想要实现的目标可能仅使用 CSS 是不可能的,因为我们结合了粘性页脚、始终可见的页脚标题(如任务栏)以及主要内容和页脚的动态高度。

我将此代码段留给可能需要粘性页脚的任何人。

fiddle : Dynamic Content with Sticky Footer

我用一个计时器来说明不断地用内容填充“上层”容器。

基本上您有以下 HTML:

<div class="wrapper">
    <div class="upper">
        <span></span>
    <div class="push">
    </div>        
    </div>

    <div class="lower">
        Footer content goes there.
    </div>
</div>​

当然还有 CSS:

.upper{
    min-height: 100%;
    height: auto !important;
    width: 100%;
    height: 100px;
    background: blue;
    margin: 0 auto -100px; /* The negative value of the footer height. */
    color: white;
}
.lower, .push {
    height: 100px; /* Footer and Push need to have equal height */
    background: red;
    color: white;
}​

代码解释:

这基本上就是所谓的 Sticky Footer 概念,您可以对其进行更多研究。您有您的主要内容,您有您的页脚,我们使用推送容器的小技巧来实际推送页脚,这样它就不会与您的任何内容重叠。

额外的CSS只是为了演示,我希望你能清理它并按照你需要的方式实现它。

关于在较低的 div 中带有 bg 图像的 HTML CSS 布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10521639/

相关文章:

html - 如何让内容 div 跨越页面的剩余高度而不滚动?

jquery - 如何使用 jquery 将 span 附加到 html 中存在的 span?

html - 多个 CSS 页面计数器

html - 如何在高度未知的情况下垂直和水平设置div?

html - 使用 CSS3 构建良好响应式设计的 "correct"逻辑方法是什么?

wpf - 按内容划分的窗口大小限制

html - 每行显示不同数量的 <li>

html - 在 Div 中居中响应式 YouTube 视频

javascript - 悬停时jQuery无限/连续滚动

html - 打破第二个 child div的字母