views:

212

answers:

5

Hi,

I have two divs in a container. One is left bar and another is right bar. I need some advice/suggestions to use which method.

Method 1:

#container{ width:800px; margin:0 auto;}
#leftbar{ float:left; width:200px; }
#rightbar{ float:right: width:550px;}

Method 2:

#container{width:800px; margin:0 auto;}
#leftbar{ float:left; width:200px; }
#rightbar{ margin:0 0 0 210px; width:550px;}

Please advice which one is good practice.

A: 

Semantically it makes no difference since 550 + 200 ~= 800 px so you are not giving any clue what the two divs should do when e.g. the container is 1000 px.

Vlagged
No i am not meaning that...Both the above CSS renders the same. but i need to know which one is the correct way of proceeding the CSS while compiling
Logesh Paul
A: 

Either is fine, but in Method 1 you will have a "gutter" of 50px between the divs, whereas it will only be 10px in Method 2.

Matt Sach
Yes you are write it will show some gutter. I just write the above code for sample only. I need to some advice to use which method?..
Logesh Paul
+1  A: 

If your container is always always always going to be 800px width then it really doesn't matter which of the two options you use. Just use the one with the least bytes per file.

But if your container gets bigger than 800px, would you want the right bar to stick to the right hand side of the container? If so, only method 1 would work.

However there is another method that achieves the same effect as method 2 which is floating both divs to the left.

sixfoottallrabbit
A: 

It makes no practical difference at this stage, but the more future-proof method is the first one, since it allows you to change the width of the container later on without having to change the rightbar css to keep it fully right-aligned.

Waggers
A: 

If you wanted to use some robust code that didn't need much thinking about, then you could use a grid-based framework such as the Yahoo User Interface, or the 960 grid.

Both offer simple-to-use CSS / HTML frameworks that enable a variety of layouts.

rnnbrwn