Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to align absolute-positioned elements below eachother?

Tags:

html

css

I have this div:

<div class="member">
    <div class="memberImage"><img src="" /></div>
    <div class="memberInfo">John Doe</div>
</div>

This is the css for it:

.member {
    width:200px;
    clear:both;
    position:absolute;
    padding:5px;
}

When I duplicate this div just beneath this one they appear to be one over the other because of the position:absolute.

Is it possible to keep the position:absolute and have them one below the other as normal?

Thanks,

like image 866
Or Weinberger Avatar asked Feb 02 '11 10:02

Or Weinberger


People also ask

How do you move positions with absolute elements?

Absolute Positioning You can use two values top and left along with the position property to move an HTML element anywhere in the HTML document. Move Left - Use a negative value for left. Move Right - Use a positive value for left. Move Up - Use a negative value for top.

How do I place a div under absolute div?

You would need to either use relative positioning on both, or absolute positioning for both and set their specific top and left values. Alternatively you could set a top margin on footer that makes it drop enough so it is positioned below the container. You also need to look at your css.

Can you center position absolute?

With a relative positioned parent element, an absolute positioned element has a boundary. And with the left , right , top and bottom properties with a value of 0 (specifying the distance of the edges), and an auto margin, the absolute element is centered in the parent element.


1 Answers

Is it possible to keep the position:absolute and have them one below the other as normal?

Simple answer: no.

Possible solutions:

  • Add a top attribute to the member class and increment for every member
  • Don't use absolute positioning (probably wisest in this case)

Judging from your code snippet you want to create a memberlist. A simple pattern that would fit well for this is simply an UL (Unordered list):

<ul class="memberlist">
    <li>
        <div class="memberImage"><img src="foo.jpg" /></div>
        <div class="memberInfo">John Doe</div>
    </li>
    <li>
        <div class="memberImage"><img src="foo.jpg" /></div>
        <div class="memberInfo">John Doe</div>
    </li>
    <li>
        <div class="memberImage"><img src="foo.jpg" /></div>
        <div class="memberInfo">John Doe</div>
    </li>
</ul>

And a corresponding CSS to go with it:

.memberlist li {
    width: 200px;
    padding: 5px;
    margin-bottom: 10px;
}
like image 112
Aron Rotteveel Avatar answered Nov 09 '22 07:11

Aron Rotteveel