基本上我需要让一个圆圈看起来像挂在一根绳子上。我使用了基本的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;
}
bottom
设置 element 的下边框到其偏移父级的距离。
要做你想做的事,你需要使用
top
:
#circle {
position: absolute;
top: 100%;
}
我写了一个小演示来可视化这一点,运行此代码片段:
<style>body{display:flex;align-items:flex-end}div{color:#693;border:solid 1px}#clip{padding-top:30px;overflow:hidden;position:relative}#outer{width:80px;height:100px;position:relative}#inner{width:15px;height:15px;position:absolute;bottom:10%;left:30px;background:currentColor}#inner:after{content:'';position:absolute;height:250px;left:50%;border-left:dashed 1px}input{writing-mode:bt-lr;-webkit-appearance:slider-vertical}</style><section> <label for="distance">bottom:</label> <output id="distanceout">10%</output><br><input type="range" min="0" max="120" value="10" step="10" id="distance" orient="vertical"></section><section id="clip"><div id="outer"><div id="inner"></div></div></section><script>distance.oninput=()=>{const percent=distance.value + '%'; distanceout.textContent=inner.style.bottom=distance.value + '%';}</script>
<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;
}