Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS positioning divs

Tags:

html

css

I'm always weak when it comes to positioning divs, but this situation is slightly difficult to find a solution to online. I'm trying to position boxes like so:

 _  ___  _ 
|_||   ||_|
 _ |   |
|_||___|

Is there a way to avoid defining each one's pixel positions specifically and make them slot into the three columns I've got?

like image 690
Sebastian Avatar asked May 28 '11 19:05

Sebastian


People also ask

How do you position a div?

If position: absolute; or position: fixed; - the right property sets the right edge of an element to a unit to the right of the right edge of its nearest positioned ancestor. If position: relative; - the right property sets the right edge of an element to a unit to the left/right of its normal position.

How do I get the top position of a div in CSS?

The top property affects the vertical position of a positioned element. This property has no effect on non-positioned elements. If position: absolute; or position: fixed; - the top property sets the top edge of an element to a unit above/below the top edge of its nearest positioned ancestor.

What are the positions in CSS?

The position CSS property sets how an element is positioned in a document. The top , right , bottom , and left properties determine the final location of positioned elements.

How do you set a div position relative to another div?

First set position of the parent DIV to relative (specifying the offset, i.e. left , top etc. is not necessary) and then apply position: absolute to the child DIV with the offset you want. It's simple and should do the trick well.


2 Answers

Define three containers for each column, and float them to the left:

<div style="float:left;width:Xpx"></div>
<div style="float:left;width:Ypx"></div>
<div style="float:left;width:Zpx"></div>

Now you can put all your containers in appropriate places in this columns.

like image 59
Headshota Avatar answered Sep 23 '22 21:09

Headshota


take a look at this fiddle: http://jsfiddle.net/rREAh/ is this what you are looking for?

If you need a perfect layout, take a look at the yahoo layout manager: http://developer.yahoo.com/yui/layout/

like image 33
rdmueller Avatar answered Sep 21 '22 21:09

rdmueller