Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Positioning a div below its' parent. position: absolute; bottom: 0; not working?

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;
}
like image 780
RonnieEXP Avatar asked Mar 24 '14 01:03

RonnieEXP


People also ask

Why is position Absolute not working CSS?

The absolute position exiles the element from natural flow. What you need to do is ie. set the margin-left to 50% of parent's width and then slide it left -50% of its own width. This won't work with relative value of element width. You must declare it absolute (like above, 200px).

How do I place a div at the bottom without absolute?

Without using position: absolute , you'd have to vertically align it. You can use vertical-align: bottom which, according to the docs: The vertical-align CSS property specifies the vertical alignment of an inline or table-cell box.

How do I move a div to the bottom of a parent?

Set the position of div at the bottom of its container can be done using bottom, and position property. Set position value to absolute and bottom value to zero to placed a div at the bottom of container.

How do you fix a position absolute?

Absolutely positioned elements are positioned with respect to a containing block, which is the nearest postioned ancestor. If there is no positioned ancestor, the viewport will be the containing block. Elements with fixed positioning are fixed with respect to the viewport—the viewport is always their containing block.


2 Answers

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%;
}
like image 134
fregante Avatar answered Nov 01 '22 19:11

fregante


<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;
}
like image 33
alessandrio Avatar answered Nov 01 '22 19:11

alessandrio