css - 使用绝对位置时,页脚未与屏幕底部对齐

标签 css

当主容器中有位置绝对元素时,我无法让页脚固定在页面底部。这是一个 fiddle进行演示。

<div class="content-wraper">
    <div class="side-nav"></div>
</div>

<div class="footer"></div>​
.content-wraper {
    background-color:blue;
    min-height:100px;
    position:relative;
    width:500px;
}

.side-nav {
    background-color:red;
    height:3000px;
    position:absolute;
    top:0px;
    left:0px;
    width:200px;
}

.footer {
    background-color:black;
    position:absolute;
    bottom:0px;
    width:200px;
    height:50px;
}

最佳答案

.footer中的position: absolute;更改为position: fixed;

Updated fiddle


更新

要使用 jQuery 将页脚固定在绝对定位的 side-nav 下方,试试这个:

$(".footer").css("top", $(".side-nav").height());

Example Fiddle

关于css - 使用绝对位置时,页脚未与屏幕底部对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13582092/

相关文章:

css - 如何每行显示两个元素而不是一个?

javascript - 错误 : Cannot read property 'top' of null

css - 具有固定边距内容容器的流体模板

jquery - 使 TD 内的表格大小与包含 TD 的表格大小相同

html - 如何使按钮高度相同?

css - 创建自定义输入类型范围跨浏览器

html - 如何在 HTML 中定位文本

javascript - textarea 中的输入不显示为输入的内容

jquery - 如何在透明图像上翻转?

html - 缩小最小屏幕时表单无响应