views:

66

answers:

4

Hello!

I have a HTML file like this (I only put the body of the page):

<body>
    <form id="form1" runat="server">
    <div class="divBody">
        <div id="divHeader">
        </div>
        <div id="leftColumn">
       Welcome!
        </div>
        <div id="rightColumn">
        </div>
    </div>
    </form>
</body>

And it css file contains this:

.divBody {
    border-style: dotted;
    border-width: medium;
    margin: 0 auto;
    width: 1024px;
    height: 768px;
    position: relative;
}
#divHeader {
    width: 100%;
    height: 70px;
    background-color: #000000;
}
#leftColumn {
    width: 33%;
    height: 100%;
    background-color: #FF0000;
    float: left;
}
#rightColumn {
    width: 66%;
    height: 100%;
    background-color: #00FF00;
}

I want a header and two columns. The header it is Ok, but columns are bigger than divBody's Height, and rightColumn doesn't fit the 66% of divBody's width.

What's happening?

Thank you.

+1  A: 

I think you need to add float-right for the rightColumn:

#rightColumn {
    width: 66%;
    height: 100%;
    background-color: #00FF00;
    float: right;
}

As for the height of the columns: I think this is because of the relative layout. To make the height of the columns fit perfectly you could calculate the exact number of pixels, like so:

#leftColumn {
   width: 33%;
   height: 698px;
    background-color: #FF0000;
   float: left;
}
#rightColumn {
    width: 66%;
    height: 698px;
    background-color: #00FF00;
    float: right;
}

(height of body - height of header = 768 - 70 = 698)

but this has the disadvantage that the columns may not grow vertically in case the body grows larger.

ANother approach would be to keep the columns 100%, but glue them to the top of the body. You must give them relative positioning to do that. In addition, you must lift them up t account for th space taken by the header:

#leftColumn {
    width: 33%;
    height: 100%;
    background-color: #FF0000;
    float: left;
    top: -70px;
    position: relative;
}
#rightColumn {
    width: 66%;
    height: 100%;
    background-color: #00FF00;
    float: right;
    top: -70px;
    position: relative;
}
Roland Bouman
Great! It works! But now I have the problem of right and left column are bigger than divBody.
VansFannel
A: 

If you are looking for something like this, I would highly recommend using YUI Grids. They've already done the work at providing the layouts (across browsers, too), and you just have to populate with your data. Very easy to use, and very nice (and the setup is similar to yours).

JasCav
+2  A: 

Your header has fixed height: 70px; and is pushing the columns down. You can add padding to divBody to counter this: see it in action.

Your also have to make your right column float otherwise it's positioned under the left column instead of being on its right.

You should rely on Blueprint or YUI 2: Grids. If you don't like CSS frameworks, there are other good resources out there like those multi-column liquid layouts.

Note: I don't know whether it's what you meant but 33% + 66% == 99% hence the gap.

Gregory Pakosz
Thank you very much for your help. I've changed 66% with 67%.
VansFannel
A: 

I think this might help you:

http://matthewjamestaylor.com/blog/equal-height-columns-cross-browser-css-no-hacks

You don't have to use a grid system and there is no extra javascript or css hacks used.

ryanulit