Domanda

Basically I need to make a circle look like it's hanging from a string. I used the basic CSS of:

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

And it's putting the circle at the bottom, but not below the "string" It's sitting on the right side of it, but at the bottom. Am I stupid? What am I doing wrong?

EDIT: Full code

<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;
}
È stato utile?

Soluzione

bottom sets the distance of the element's bottom border to its offset parent.

To do what you want, you need to use top:

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

Demo

I wrote a little demo to visualize this, run this code snippet:

<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>

Altri suggerimenti

<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;
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top