Forum Moderators: not2easy

Message Too Old, No Replies

interdependent height of the DIVs

how can I make two divs to have the same height?

         

Fokel

2:21 am on Oct 11, 2008 (gmt 0)

10+ Year Member



Hi,

This might be very simple question, but for some reason it is a stumbling block for me.

I have two divs, and I want both of them to have the same height - 100% of the screen.

i want them to be just like two colomns of the table, which extends to 100% of the screen. If one colomn is filled with content, the second has to be the same height even if it is empty.

But how can I achieve the same result using css?

I thought that all I need was to set [body] height to 100%, and also set height of both divs to 100%.
But it only makes them to be 100% of the screen before I scroll it down. when one div is more long (with a lot of content inside) and a vertical scrollbar appears in a browser, the second div remains the same size and after I scroll my page down it is an empty space under it!

code:


<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html">
<style type="text/css">
<!--
body {
height: 100%
}
.right {
position:absolute;
height: 100%;
width: 200px;
left: 500px;
top: 0px;
background-color: red
}
.left {
position:absolute;
height: 100%;
width: 170px ;
left: 0px;
top: 0px;
background-color: blue
}
-->
</style>
</head>

<body bgcolor="#FFFFFF">
<div id-left class=left>
<p>content that is too much</p>
<p>content that is too much</p>
<p>content that is too much</p>
<p>content that is too much</p>
<p>content that is too much</p>
<p>content that is too much</p>
<p>content that is too much</p>
<p>content that is too much</p>
<p>content that is too much</p>
<p>content that is too much</p>
<p>content that is too much</p>
<p>content that is too much</p>
<p>content that is too much</p>
<p>content that is too much</p>
<p>content that is too much</p>
<p>content that is too much</p>
<p>content that is too much</p>
<p>content that is too much</p>
<p>content that is too much</p>
<p>content that is too much</p>
<p>content that is too much</p>
<p>content that is too much</p>
<p>content that is too much</p>
<p>content that is too much</p>
<p>content that is too much</p>
<p>content that is too much</p>
<p>content that is too much</p>
<p>content that is too much</p>
<p>content that is too much</p>
<p>content that is too much</p>
<p>content that is too much</p>
<p>content that is too much</p>
<p>content that is too much</p>
<p>content that is too much</p>
<p>content that is too much</p>
<p>content that is too much</p>
<p>content that is too much</p>
<p>content that is too much</p>
<p>content that is too much</p>
<p>content that is too much</p>
</div>

<div id=right class=right>
<p>a little content</p>
</div>
</body>
</html>

how to make red box the same size as blue? without using a table?

Fokel

5:23 am on Oct 11, 2008 (gmt 0)

10+ Year Member



the only working solution I've found, was javascript.
two steps:
1. find the "longest" div in the page.
2. assign that height to all the rest divs.

but I am not sure that it is good method, and how "crossbrowser" is it.

And I still hope to solve problem with css/html adjusting.

alt131

10:35 am on Oct 11, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Fokel!

2, 3, Multi Column CSS Templates and Layouts [webmasterworld.com] in the forum library has a good selection of examples, and the one entitled "2 Column, 100% height, with Header and Footer" could be modified for your purpose.

Otherwise there are multiple example sites that will show up in a search.

Fokel

12:48 pm on Oct 12, 2008 (gmt 0)

10+ Year Member



thank you, alt131!
some really good templates in your link, though not exactly what I need in this particular case (special design with combination of images and non-repeating backgrounds in different places, that require weird tricks).
Anywasy, as I see, similar problem was discussed many times on the net... since javascript variant works well, I have time to search!