html - 如何将这个div放置到页面底部

标签 html css

我一直试图让页脚粘在页面底部。

这是基本布局:

<div id="div-header"></div>     
<div id="div-body">
    <h2>Some content</h2>
    <div id="div-left">Left content</div>
    <div id="div-right">
        right content
    </div>
</div>
<div id="div-footer-bottom"></div>

这就是我设计页脚的方式:

#div-footer, #div-footer-bottom{
    background-color: red;
    border-top: 1px solid #CCCCCC;
    height: 40px;
    padding: 20px 30px;
    text-align: right;

}

#div-footer-bottom{
    position: relative;
    clear: both;
}

如下所示,当浏览器缩放至 100% 时,页面呈现正常: enter image description here

但是,例如,如果浏览器缩放至 120%,则页面的显示方式如下:

enter image description here

请查看 jsfiddle 中的完整代码以发现我做错了什么,因为我不知道还能尝试什么:

http://jsfiddle.net/RS88D/

提前致谢。

最佳答案

尝试添加以下CSS

#div-footer-bottom{
    position: fixed;
    bottom:0;
    left:0;
    clear: both;
    width:100%;
}

重叠

margin-bottom 添加到 div-left。边距应等于页脚的高度(还添加填充像素)。对于你的情况

#div-left
{
  margin-bottom: 80px;
}

2014 年 3 月 24 日更新

对于您的第一个 fiddle 详细信息,只需添加以下内容并尝试,

body, html
{
      height:100%;
}

并在 #div-body css 中,删除 min-height: 490px; 并添加 min-height: calc(100% - 190px);

关于html - 如何将这个div放置到页面底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22580313/

相关文章:

javascript - 如果图像高度超过图像宽度,通过裁剪图像的顶部和底部来垂直居中图像 - 仅使用 CSS 可能吗?

php - 回显边框底部 php

css - 将 css 类或 id 分配给 cakephp 中的工具提示

php - Codeigniter URI 路由和安全

JavaScript 更改具有相同 ID 困境的元素的值

javascript - 如何使用 CSS 动画创建无限符号轨迹?

html - XHTML 1.0 Strict 中图像下方不需要的间距

html - 如何修改primeng p日历样式?

iphone - 如何在 iphone 应用程序中解析 HTML 页面数据?

javascript - 如何根据当前时间更改 div 的颜色?