2

I want to develop 4 column layout ( in addition to mastead and footer which takes the full available width of the page) such that right-most column is fixed at 200px and others are fluid subject to min-width = 960px and max-width= 1216px.

So this means as long as the browser window is greater than 960 and less than 1216 px wide, the layout acts like liquid layout. Once the browser window is larger than 1216, it acts as fixed layout with the width= 1216px and the page centered in the browser viewport. If the browser window is shrunk to less than 960px, horizontal scrollbar at bottom would appear because min-width is 960px.

I liked the grid system of developing website layout (example http://960.gs/).

The doctype on my webpage would be <!DOCTYPE html> (aka html5 doctype)

The solution should work for IE 6 7 8 9 and FF, Safari, Chrome, Opera.

Hopes this makes it clear what I am looking for.

What is the solution to this problem based on the conditions given above?

I researched google but could not find any solution. I come across solution like 3 column with max-width but without grid system and looked too clumsy.

Later I have to add support for small screen (Mobile devices) which would require setting some column to display:none and stacking other columns on top of each other by using media queries but first I need to get past above problem.

thirtydot
  • 224,678
  • 48
  • 389
  • 349
ace
  • 11,526
  • 39
  • 113
  • 193
  • There are all kinds of `max-width` hacks for IE6, have you done any research? What have you tried so far? We're not going to build the entire system to your specifications for you, that isn't how SO works. – user229044 Jan 17 '11 at 14:28
  • 4
    On an unrelated note, the 960 grid system is silly, and goes against the express intent of CSS - decoupling display from semantics. – user229044 Jan 17 '11 at 14:29

1 Answers1

3

I tested this in IE7/8 and recent versions of Chrome, Firefox, Opera, Safari.

This will not work in IE6 (as @meagar said) because of min-width and max-width - there are plenty of resources online detailing hacks to get around this. I'm not going to expend effort on doing this myself unless the rest of my code is correct for you. Also, I have no interest in using a CSS grid system.

Live Demo (with taller right column)
Live Demo (with taller fluid column)

HTML:

<div id="container">
    <div id="header">header</div>
    <div id="fluidColumnContainer">
        <div class="column">column 1</div>
        <div class="column">column 2</div>
        <div class="column">column 3</div>
    </div>
    <div id="fixedColumn">i'm 200px wide!<br />o<br />o<br />o<br />o</div>
    <div id="footer">footer</div>
</div>

CSS:

html, body {
    margin: 0;
    padding: 0;
    border: 0
}
#container {
    margin: 0 auto;
    min-width: 960px;
    max-width: 1216px;
    overflow: auto
}
#fluidColumnContainer {
    padding: 0 200px 0 0
}
#fixedColumn {
    width: 200px;
    float: right
}
.column {
    float: left;
    width: 33%
}
#header {
    height: 90px
}
#footer {
    height: 90px;
    clear: both
}
thirtydot
  • 224,678
  • 48
  • 389
  • 349
  • This design looks very clean but it comes at a cost, it does not work after you start adding margins and/or padding borders around those columns which is what needs to be done in production system! – ace Jan 18 '11 at 15:28
  • Also it is not based on grid system but I can forget about grid system if I have working and flexible design as well as clean design. – ace Jan 18 '11 at 15:30
  • By not working I mean after I add margin to all columns and some content to middle column, column 3 goes below column one! – ace Jan 18 '11 at 15:33
  • I made some progress to make it work by adjusting the percentage widths of columns, it seems these percentages don't take into account margins/padding. – ace Jan 18 '11 at 15:50
  • By far the easiest way to do the things you're asking about is to add an extra `div` inside each `.column` (like this: `
    column 1
    `). Then, CSS like this: `.column div {padding: 10px; border: 8px solid red; margin: 10px}`. If this answers your question, please [accept my answer](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work#answer-5235).
    – thirtydot Jan 18 '11 at 16:27
  • Careful with this answer. The #fluidColumnContainer has height 0, which may not be what you want, as explained here http://stackoverflow.com/questions/6591108/why-does-order-of-float-div-and-non-float-div-matter-only-in-some-cases/6591287#6591287 – huyz Jul 06 '11 at 04:01
  • @huyz: Reading your question, I can see how you became confused. When I wrote this, not clearing the floats inside `#fluidColumnContainer` seemed to be the cleanest solution, because it avoided having to reorder the elements. – thirtydot Jul 06 '11 at 11:28