views:

165

answers:

2

Hi all, I'm trying to create a website and it's design is forcing me to use multiple backgrounds. I'm talking about a technique that looks like this

    <div id="left">
         <div id="left_1">
              <div id="left_2">

              </div>
         </div>
    </div>

#left{
 width:235px; 
 margin:0; padding:0; float:left;
 background:url(../images/left_middle.jpg) top left repeat-y;
}
#left_1{
 width:235px; 
 margin:0; padding:0; float:left;
 background:url(../images/left_top.jpg) top left no-repeat;
}
#left_2{
 width:218px; 
 margin:0; padding:0 0 0 17px; float:left;
 background:url(../images/left_bottom.jpg) bottom left no-repeat;
}

At the same time a have to create an equal div/column height structure for the page.

<div id="container">

     <div id="left">
          <div id="left_1">
               <div id="left_2">

               </div>
          </div>
     </div>

     <div id="center">

     </div>

     <div id="right">
          <div id="right_1">
               <div id="right_2">

               </div>
          </div>
     </div>
</div>

The #left, #center and #right divs should have the same height and look full with background. I have read a lot of techniques through internet about the equal-height-divs but adding the multiple backgrounds issue, makes it impossible for me to find a solution here.

I was wondering if someone could help me out there. Thanks in advance

alt text

+1  A: 

Save yourself the trouble and just use tables for the outer layout. They just work.

Here's the table example:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;
<html>

<head>
<title>left</title>
    <style type="text/css">
        .side { background-color:blue;color:white;width:235px;vertical-align:top;margin:0px;padding:0px;}
        .left3 {padding:0px 0px 0px 17px;vertical-align:top;}
        .mainContent {margin:0px;vertical-align:top;}
        table {width:100%;height:100%;border-collapse:collapse;}
        html,body{width:100%;height:100%;margin:0px;}
    </style>
</head>

<body>
<table>
    <tr>
        <td class="side">left
            <table>
                <tr><td class="side">left side 2
                    <table><tr><td class="left3">Left Side 3</td></tr></table>
                </td></tr>
            </table>
        </td>
        <td class="mainContent">center</td>
        <td class="side">right</td>
    </tr>
</table>
</body>

</html>
Chris Lively
you mean replacing "all" divs by tables and cells or just "some specific" divs?
ktsixit
+1 for reality-based answer. Sometimes div/css layouts are more trouble than they are worth.
Ray
@ktsixit: I generally use a combination of tables and divs. In this case I would use tables to get the heights exactly as I need them. Most of the content areas inside I would do as divs so that they could adjust as necessary.
Chris Lively
+1. Death to the "death to tables"-crowd!
Wim
@Chris Lively, I tested the table solution but it works only in firefox. In IE and all other browsers, the tables and cells inside the main wrap table, don't expand their height 100%. They behave just like divs, adjusting their height depending on their contents. Although I have set "height:100%" for all tables and cells.
ktsixit
@ktsixit: Just added sample code. It works in IE8, FF3.6, Chrome, and Safari. I don't know about other versions of IE or FF because I don't have them. But considering it's HTML 4.01 Strict, their rendering engines ought to do just fine.
Chris Lively
Also, obviously you can just add your backgrounds as you want..
Chris Lively
I just saw the new example code you posted. I'll test it. My test version was a bit different that yours
ktsixit
+1  A: 

if you don't mind using javascript/jquery, you can add this to your html:

<script type='text/javascript'
 src='http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js'&gt;&lt;/script&gt;

<script type='text/javascript'>
$(document).ready(function() {

    // get the heights
    l = $('#left_2').height();
    r = $('#right_2').height();
    c = $('#center').height();

    // get maximum heights of all columns
    h = Math.max(c, Math.max(l, r));

    // apply it
    $('#left_2').height(h);
    $('#right_2').height(h);
    $('#center').height(h);
    });
</script>
widyakumara
I tested what you suggested and it works fine:) Do you think it's risky to use javascript for this issue?
ktsixit
well, as far as i can tell, no risk at all, as most modern browsers support this, and most people probably enable it [citation needed :P]there are several css only solutions, tho. but sometimes when background images are involved, it's getting tricky, especially cos we have to deal with cross-browsers compatibility.anyhow, check these out:- http://www.ejeliot.com/blog/61- http://redmelon.net/tstme/3cols2/- http://www.456bereastreet.com/archive/200405/equal_height_boxes_with_css/- http://matthewjamestaylor.com/blog/equal-height-columns-cross-browser-css-no-hacks
widyakumara