views:

97

answers:

5

I need the red box to expand with the blue box content, so they are always both the same size.

alt text

The red box is defined as:

.leftMenu{
    float:left;
    width:20%;
    background-image:url(../images/leftMenuBG.jpg);
    background-position:bottom;
    background-color:#BFDAE3;
    background-repeat:repeat-x;
}

Can't seem to get it to work, whatever I try! Any ideas? Thanks!

+4  A: 

Simple solution: Use tables.

Semantic solution: Use faux columns.

Magnar
+1 for being bold enough to suggest the correct solution (tables).
Aaron Digulla
Using tables for layout... have we gone back to the 80's??
jimplode
I got slated for doing some table code for something else that could only apparently be done with tables, but i dont see the problem if they work and solve simple problems like this, thanks for the answer.
Tom Gullen
@Aaron You've got a funny definition of correct over there. Does the information in the screenshot look tabular to you?
Yi Jiang
Tables should NEVER be used for layout, all sorts of accessibilty issues with screen readers, and is far more markup, becomes messy and hard to maintain/change. Tables should only EVER be used for tabular data.
jimplode
@Yi Jiang: He wants two elements with the same height. A table is the only HTML/CSS element which guarantees that. Everything else is just a hack.
Aaron Digulla
@jimplode: Never use never. The correct rule is: You should use tables when they make **sense** instead of **always**.
Aaron Digulla
@Aaron: Tables should only ever be used for tabular data. Should never be used for layout. To produce what was asked here is easy with simple div structure, see my answer.
jimplode
@jimplode: `TD` is the only HTML element which supports "same height". `TD` -> table. What you suggest is a hack that breaks if you add background, padding, margins, etc.
Aaron Digulla
@Aaron: You are sadly mistaken and clearly don't know your HTML or CSS. How is using the markup and css in the way is it suppose to be used a hack? I have never found a website structure I cannot make using only css and divs. Tables should be used for "tabular" data, not layout of a site.
jimplode
@jimplode: I would like to say the same about you. Not everyone has weeks to debug some weird CSS bugs on 3 different browsers. I also fail to understand why most CSS designers are so damn proud that they can come up with more complex over more simple solutions.
Aaron Digulla
@jimplode: Oh and about your boast: Please create a greek border around a fixed-width site menu (on the left of the page) that must not shrink less tall than 8 lines of text (even when there is only one) and must expand by multiples of the border image size so the pattern doesn't get distorted. The inner area of the menu must show the same background as the main content. FF3+, IE6+, Opera9+
Aaron Digulla
@Aaron: Even W3C say you should not use tables for layout. http://www.w3.org/TR/WCAG10-CSS-TECHS/#style-alignment So before you try and argue your point please make sure you actually know what you are urguing about. Tables should only be used to display tabular data, like an excel spreadsheet. This is why we have professional web developers, otherwise everyone would just use dreamweaver and make a crap job out of a simple task!
jimplode
+2  A: 

You will need to wrap the red div around the blue div, so have the blue divs inside, floated right, and then have a clearing div after the blue divs.

<div style="border:solid red 2px;">
    <div style="border:solid blue 2px;float:right;width:200px;">
        <p>Content here</p>
    </div>
    <div style="clear:both;"></div>
</div>

Excuse the use of inline styles, these should be in a style sheet.

jimplode
And obviously setting the inner (blue) div to cover the outer (red) divs background colour?
pete the pagan-gerbil
that would work, or you could just use background imagery and use background-position to make sure it was in the right place.
jimplode
A: 

If you need each div to sit independently of each other and don't mind using JavaScript (as this is only a presentational layer) try this method.

graham
A: 

You can use a jQuery plugin for that too. (for example, http://www.cssnewbie.com/equal-height-columns-with-jquery/)

But the Semantic solution: Use faux columns. from Magnar is nice too and doesn't require Javascript.

Chouchenos
A: 

An additional 'faux column'-method is to (ab)use positioning.

Place both boxes inside a container that's floated (which makes it expand to accomodate floated children) and positioned relatively (which allows us to position child elements inside it).

Then, position the shortest column absolutely, and float the longest column. The container will take on the height of the floated child, and the div with position:absolute will take that height again.

A short example:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd"&gt;
<html>
<head><title>Columns</title>
<style type="text/css">
html, body {
    width: 100%;
}

#container {
    width: 100%;
    float: left;
    position: relative;
    border: 2px solid black;
}

#left-box {

    position: absolute;
    width: 40%;
    border: 2px solid red;
    background-color: #5555ee;
    height: 100%;
}

#right-box {
    float: right;
    margin-right: 15%;
    width: 40%;
    border: 2px solid blue;
    background-color: #3e3e3e;
}
</style>
</head>
<body>
<div id="container">
    <div id="left-box">
    - E - x - P - a - N - d - I - n - G -
    </div>  
    <div id="right-box">
        <p>
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed mattis eros ut sem sollicitudin ultricies. Vivamus pharetra, urna sit amet auctor mollis, risus sem ultrices quam, non condimentum enim leo sit amet tellus. Pellentesque id vehicula nisl. Nulla ut commodo ligula. Sed sit amet ligula purus, at suscipit leo. Nulla quis nulla id est aliquet vehicula. Suspendisse consectetur, nunc in hendrerit dignissim, nisl massa viverra quam, et faucibus augue lorem eu mi. Vestibulum commodo luctus ante, vel placerat metus ullamcorper vel. Sed id imperdiet orci. In hac habitasse platea dictumst. Praesent ac dui orci, vitae pharetra dolor.
        </p>
        <p>
        Aenean enim metus, placerat at hendrerit in, hendrerit in velit. Cras tincidunt blandit sapien, a aliquet elit sollicitudin vitae. Quisque at ligula sem. In hac habitasse platea dictumst. Ut eu magna ipsum, id fringilla massa. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Vivamus consequat metus sed lectus dignissim posuere quis a felis. Mauris in consectetur arcu. Nullam fermentum adipiscing dignissim. Sed quis orci in magna viverra sollicitudin. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Maecenas condimentum lectus pretium tortor porta a hendrerit dui pharetra. Etiam est justo, bibendum vehicula vestibulum ac, mattis ut risus. Praesent dapibus nibh id enim vestibulum porta. Donec aliquam urna a diam varius blandit. Nulla interdum ante at arcu vehicula sagittis. Curabitur quam sapien, luctus ac sagittis vitae, tristique a odio. Nulla consequat gravida urna, at bibendum nisl ultricies ac.
        </p>

        <p>
        Vivamus quis metus porta purus aliquet aliquet. Morbi sollicitudin orci ut ligula vehicula sollicitudin. Etiam sed lacus eget leo molestie ullamcorper sit amet ac urna. Cras vitae turpis in sapien dignissim molestie. Curabitur tellus purus, dignissim at adipiscing in, faucibus ac tortor. Duis vitae metus ac urna cursus consequat eget vel quam. Integer bibendum mauris enim, sit amet blandit sapien. Nam in lectus ante. Curabitur lacinia erat sit amet lectus malesuada facilisis. Phasellus et pellentesque enim. Fusce eget tristique est. Suspendisse id dui eu lorem congue tincidunt. Cras libero lectus, placerat eget tristique a, gravida vitae lorem. Sed nec venenatis sapien. Suspendisse tempus orci ut odio venenatis et cursus sem faucibus. Mauris commodo ultricies dictum. Curabitur iaculis, ligula sit amet lobortis hendrerit, eros orci elementum nisi, cursus lacinia nunc felis vitae erat. Donec id elementum ipsum.
        </p>
        <p>
        Mauris id mi sed augue egestas vestibulum non a ipsum. Ut arcu purus, consequat in tincidunt in, pretium a dui. Cras in quam tellus, non ultricies nisi. Sed leo orci, gravida et luctus sed, eleifend quis odio. Praesent cursus feugiat neque, tincidunt malesuada libero egestas sit amet. Etiam nisi nisi, faucibus vitae accumsan sed, gravida ut lacus. Suspendisse hendrerit fringilla interdum. Cras fermentum nibh non eros gravida pretium et a sem. Sed non nisl dui, non commodo arcu. Donec nec massa mi, vel auctor odio. Curabitur sagittis velit id felis egestas iaculis. Nunc pharetra magna eu metus malesuada ut porta mi suscipit. Aenean vitae elit sit amet neque pellentesque malesuada. Aliquam eu nulla consectetur est adipiscing vulputate non a odio. Sed consectetur neque eros. Nulla fermentum vehicula vestibulum. Aenean eleifend, nisi eget porta accumsan, tellus orci tincidunt metus, volutpat lobortis quam augue commodo tellus. Aenean consectetur pretium vestibulum. Pellentesque a scelerisque sem. Cras pellentesque tortor euismod magna viverra mollis.
        </p>
        <p>
        Mauris dignissim sodales placerat. Sed id interdum erat. Nunc sagittis, nunc in auctor ullamcorper, nisi dolor commodo sem, sit amet aliquam diam dolor posuere est. Ut vestibulum elit ut urna imperdiet non tincidunt sapien euismod. Fusce ut sem erat, aliquam accumsan metus. Proin sed velit nec velit laoreet dignissim at sit amet ante. Pellentesque ac dolor non nulla dapibus lacinia. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Suspendisse non nisl diam. Sed et ligula sed libero porttitor semper eget eu elit. Phasellus quis massa dolor. Phasellus ac justo ac diam ultrices iaculis quis at odio. Fusce eget nisi nunc. Cras cursus, dui eget mattis rutrum, arcu dolor sollicitudin nibh, eu congue augue quam ut leo. Praesent in est nulla, eu ullamcorper enim. Nullam in adipiscing ligula.
        </p>    
    </div>
</div>
</body>
gnud