将div定位在'之下家长。位置:绝对;底部:0;不工作?

时间:2014-03-24 01:37:36

标签: html css css-position

基本上我需要让一个圆圈看起来像挂在绳子上。我使用了基本的CSS:

#string {
    position: relative;
}
#circle {
    position: absolute;
    bottom: 0;
}

它将圆圈放在底部,但不是在“弦”下方。它位于它的右侧,但位于底部。我傻了吗?我做错了什么?

编辑:完整代码

<div class="anchor" id="one">
    <div class="circle" id="one">
    </div>
</div>

html, body { height: 100%; width: 100%; }
body {
    font: 100%/1.4 Verdana, Arial, Helvetica, sans-serif;
    background: #DDD;
    margin: 0;
    padding: 0;
    color: #000;
}
.anchor {
    background-color: #000;
        position: relative;
    width: 10px;
}
.anchor#one {
    margin-left: 10%;
    height: 500px;
}
.circle {
    position: absolute;
    bottom: 0;
    border-radius: 50%;
    background-color: #000;
}   
.circle#one {
    width: 200px;
    height: 200px;
}

2 个答案:

答案 0 :(得分:7)

bottom设置元素的底部边框与其偏移父级的距离。

要做你想做的事,你需要使用top

#circle {
    position: absolute;
    top: 100%;
}

答案 1 :(得分:1)

<div class="anchor" >
    <div class="circle" >
    </div>
</div>

CSS

.anchor {
    background-color: #000;
    position: relative;
    width: 10px;
    margin-left: 10%;
    height: 500px;
}
.circle {
    position: absolute;
    bottom: -200px;
    border-radius: 50%;
    background-color: #000;
    width: 200px;
    height: 200px;
    left: -100px;
}
相关问题