I want to make a two column layout using DIVs, where right column will have a fixed width of 200px and the left one would take all the space that is left.
It's quite easy, if you use tables:
<table width="100%">
<tr>
<td>Column 1</td>
<td width="200">Column 2 (always 200px)</td>
</tr>
</table>
But how about DIVs? Is it possible to accomplish this? If yes, then how?
CSS:
HTML:
The above should work, you can put that code in wrapper if you want the give it width and center it too,
overflow:hidden
on the column without a width is the key to getting it to contain, vertically, as in not wrap around the side columns (can be left or right)IE6 might need
zoom:1
set on the #content div too if you need it's supportHere's a solution (and it has some quirks, but let me know if you notice them and that they're a concern):
CSS Solutuion
Check working example at http://jsfiddle.net/NP4vb/3/
jQuery Solution
Check working example http://jsfiddle.net/NP4vb/
The following examples are source ordered i.e. column 1 appears before column 2 in the HTML source. Whether a column appears on left or right is controlled by CSS:
Fixed Right
Fixed Left
Alternate solution is to use display: table-cell; which results in equal height columns.
I was recently shown this website for liquid layouts using CSS. http://matthewjamestaylor.com/blog/perfect-multi-column-liquid-layouts (Take a look at the demo pages in the links below).
The author now provides an example for fixed width layouts. Check out; http://matthewjamestaylor.com/blog/how-to-convert-a-liquid-layout-to-fixed-width.
This provides the following example(s), http://matthewjamestaylor.com/blog/ultimate-2-column-left-menu-pixels.htm (for two column layout like you are after I think)
http://matthewjamestaylor.com/blog/fixed-width-or-liquid-layout.htm (for three column layout).
Sorry for so many links to this guys site, but I think it is an AWESOME resource.