tags:

views:

33

answers:

2

In fixed width layout if width of layout is already defined in #wrapper {width:970px} then

what should i add to inner div which i want to expand fully .like for header, footer, banner etc

  1. same width:970px to all div also
  2. No need to define any width
  3. or width:100% should be added
A: 

I think the correct answer is number 2.

divs by default take as much horizontal space as they can.

Anyways you might fine more detailed answers in http://doctype.com (like SO but design oriented).

Regards!

Edit: There's an interesting discussion about this topic here

Pablo Fernandez
+1  A: 

Either 2 or 3..

Hardcoding the same value more than once (case 1) will only lead to trouble and more work whenever you decide to change the size of the wrapper..

And from 2 and 3, better use 2 ( as @Pablo mentioned)

  1. because it is greedy and will expand to its parent width.
  2. because you can add additional properties like border/padding/etc that affect its size, without having to make manual adjustments..
Gaby
but what is the difference in 2 and 3. Aren't both same? is 100% will behave different than no width defined
metal-gear-solid
Yes.. If you define width 100% then it will be calculated to 970px. So adding padding to that will exceed this size and push or overflow the wrapper.. on the other hand if you leave it undefined it will take into consideration the padding/borders/etc before expanding to 100%
Gaby
@Gaby pls can u explain this by example?
metal-gear-solid
@Jitendra, have a look at this page i just made that show these cases.. http://jsbin.com/ikera3/3 (IE will expand the wrapper to fit contents but it is a bug..)
Gaby