css - DIV定位(多个div,不同Z索引)

标签 css

此问题已发布多次,但我找不到可以帮助我找到解决方案的讨论。 在 #AnotherDiv 移动后,我怎样才能摆脱底部的这个额外空间? 我也尝试了其他设置,比如使用外部 div(宽度 100%)并将 #content#AnotherDiv 放在里面,然后是 #AnotherDiv 根本不会停留在底部(我使用了 position absolutebottom 0)。我想要的只是让 #AnotherDiv 在页脚 div 的底部对齐。

http://jsfiddle.net/bW7h2/10/

#AnotherDiv {
    position: relative;
    bottom: 200px;
    width: 100%;
    height: 200px;
    z-index: 1;
    background-color: #00FF00;
}

最佳答案

#AnotherDiv 元素使用 margin-top: -200px; 而不是 bottom:200px;
你的 CSS 中缺少 ;:

LIVE DEMO

#homepage{
    width: 100%;
    height: 100%;
    padding: 0px;
    margin: 0;
}
/* Header, Body, Footer */
#content {
    position: relative;
    width: 900px;
    margin-left: auto;
    margin-right: auto;
    background-color: #0000FF;
    z-index: 1;        /* 1 IS QUITE ENOUGH, SET '0' FOR #AnotherDiv */
}

#data {
    position: relative;
    width: 100%;
    min-height: 500px;
}
#footer {
    height: 200px;
    width: 100%;  /* MISSING ; */
    position: relative;
    background-color: gold;
}

#AnotherDiv {
    position: relative;
    width: 100%;
    height: 200px;
    z-index: 0;
    margin-top: -200px;  /* INSTEAD OF bottom:200px; */
    background-color: #00FF00;
}

关于css - DIV定位(多个div,不同Z索引),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16133204/

相关文章:

html - 将阴影和 z-index 应用于绝对定位元素

javascript - 导轨 : get hoverover popup in form

html - 动画后需要删除CSS文本

javascript - 悬停/点击/jquery 事件的字体渲染问题

html - 如何仅设置有序列表项的样式?没有嵌套在里面的无序列表项

javascript - 整个屏幕变灰,包括滚动条

javascript - 如何使用 CSS 和 javascript 为 X 数量的 div 设置动画?

javascript - 带有 modal=true 的 Primefaces 对话框无法正常工作

Firefox 中特定最大宽度的 C# 媒体查询

css - less 中的嵌套样式,样式父级和子级