/    Sign up×
Community /Pin to ProfileBookmark

"Stretching" container divs to fit 2 column content

This seemingly simple problem has been tormenting me- I have tried everything from overflows to clears, to more complicated hacks, and nothing seems to work. Perhaps someone here knows how to deal with this- here’s the situation:

The webpage itself has 2 columns (a main content area and a nav column
on the right). Within the main content area, I have a container div,
which itself has 2 columns. The content within the 2 columns is
dynamic, and sometimes the rcol will be longer (height), and other times the
lcol will be longer.

No matter what I try to do, I cannot get the container div to “stretch”
to fit both columns. Sometimes it will work in IE (probably because
it’s not compliant), but not in FF. On a couple hack solutions, it will work in FF but not in IE. The longer of the two columns will
inevitably overflow beyond the container bottom border (or sometimes be cut off).

I cannot simply do a Clear Both, because that will clear it beyond the content of the right-hand nav column on the page.

Below is a simplified version of the problem, both the css and html. (I made the heights fixed, but in my real problem, the heights are dynamic and either column could be higher).

CSS:

#wrapper{
background-color: #336699;
height: 500px;
width: 700px;
margin: auto;
}

#nav{
float: right;
background-color: #CC6600;
height: 475px;
width: 200px;
}

#content{
margin-left: 20px;
float: left;
background-color: #CCCCCC;
width: 420px;
}

#column1{
margin-left: 4px;
float: left;
height: 300px;
border: 2px solid #000000;
width: 200px;
}

#column2{
margin-left: 4px;
float: left;
height: 200px;
border: 2px solid #334455;
width: 200px;
}

HTML:

<div id=”wrapper”>

<!– start nav –>
<div id=”nav”>

</div>
<!– end nav –>

<!– start content –>
<div id=”content”>
<!– start column1 –>
<div id=”column1″>
</div>
<!– end column1 –>
<!– start column2 –>
<div id=”column2″>
</div>
<!– end column2 –>

</div>
<!– end content –>

</div>

to post a comment
CSS

9 Comments(s)

Copy linkTweet thisAlerts:
@KravvitzFeb 22.2006 — It looks like you should use [url=http://www.dynamicsitesolutions.com/css/min-height_for_msie/]min-height[/url] instead of height.
Copy linkTweet thisAlerts:
@showpeiauthorFeb 22.2006 — The heights in the example I made are more for illustration of the problem, and they are arbitrary. The actual page I am working on doesn't have absolute heights for the columns- the content within the columns is dynamic, so the heights could be anything.

The main issue I am trying to figure out is how to make the container div expand to fit the content of both columns, regardless of size.
Copy linkTweet thisAlerts:
@ronalfyFeb 23.2006 — Any chance of you giving us a link to your site? This may be an obvious question, but do you have a doctype specified? If not, I would add in the XHTML strict or transitional doctype and see if that fixes your problem. IE acts really dumb without a doctype. If that's not the problem, I'd like to see your site so I can personally download the source code and try it out.
Copy linkTweet thisAlerts:
@KravvitzFeb 23.2006 — Do you mean you want #wrapper to stretch so that nothing overflows it?

#wrapper{
background-color: #336699;
width: 700px;
margin: auto;
[b]overflow:auto;[/b]
}
Copy linkTweet thisAlerts:
@showpeiauthorFeb 23.2006 — Kravvitz - I think you are very close to a solution that works for me. I added "overflow: auto" to my wrapper, and it takes care of the problem in Firefox. In IE, if column1 is taller than column2, it works fine also. The only problem occurs when column2 is taller than column1 in IE - the content still overflows outside of the wrapper. Any idea why this might be happening?


ronalfy - The site is in mid-development right now, and it would be a slight pain for me to extract a viewable page for people to see. I'll go ahead and do that though if I can't get the answers I need from the info I already provided. To answer your other question- yes, I have a doctype defined:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Copy linkTweet thisAlerts:
@KravvitzFeb 23.2006 — I suggest you read these articles that explain some of IE's wierd behavior.

http://www.satzansatz.de/cssd/onhavinglayout.html

http://dean.edwards.name/weblog/2005/06/layout/

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/IETechCol/cols/dnexpie/expie20050831.asp

Why are you using XHTML 1.0 Transitional? Why not XHTML 1.0 Strict or HTML 4.01 Strict?
Copy linkTweet thisAlerts:
@showpeiauthorFeb 23.2006 — Thank you- with your help, I was able to go in there and play around with the layout and I believe I finally came up with something that works in both browsers.
Copy linkTweet thisAlerts:
@showpeiauthorFeb 23.2006 — btw, is there a problem with using XHTML 1.0 Transitional as opposed to Strict? I figured that some of our users would be using older browsers, so I went with that one.
Copy linkTweet thisAlerts:
@KravvitzFeb 23.2006 — You're welcome ?

The major difference between them is that strict doesn't allow most of the presentation attributes and elements that transitional does. Whether you use transitional or strict makes little if any difference to the browser.
×

Success!

Help @showpei spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...