DIV定位(多个div,不同Z指数)

时间:2013-04-21 16:07:48

标签: css

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

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

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

2 个答案:

答案 0 :(得分:0)

我从您的评论中了解到您想要这样做吗?

#AnotherDiv {
    position: fixed;
    bottom: 0px;
    width: 100%;
    left: 0;
    right: 0;
    height: 20px;
    z-index: 101;
    background-color: #00FF00;
}

答案 1 :(得分:0)

margin-top: -200px;元素使用bottom:200px;代替#AnotherDiv 你错过了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;
}