/    Sign up×
Community /Pin to ProfileBookmark

Need container div’s height to resize with floating children

Im using divs instead of tables to arrange items on my web page but when I use float:left on children element the parent element (the container) doesn resize, it stays at height = 0px. How can I fix this? A simple example below

[CODE]
<html>
<head>
</head>
<body>
<style type=”text/css”>
#container{
width:400px;
background-color:blue;
}
#content{
position:relative;
width:400px;
height:200px;
background-color:red;
float:left; /* the container height resizes if I skip this */
}
</style>
<div id=”container”><!– this guy stays at 0px height if it’s children float is set –>
<div id=”content”></div>
</div>
</body>
</html>
[/CODE]

to post a comment
CSS

2 Comments(s)

Copy linkTweet thisAlerts:
@aj_nscAug 25.2010 — #container { overflow: hidden; }

Point (d) on sitepoint -> http://www.sitepoint.com/blogs/2005/02/26/simple-clearing-of-floats/
Copy linkTweet thisAlerts:
@tralliauthorAug 25.2010 — #container { overflow: hidden; }

Point (d) on sitepoint -> http://www.sitepoint.com/blogs/2005/02/26/simple-clearing-of-floats/[/QUOTE]


wow simple, yet not obvious solution, thanks alot
×

Success!

Help @tralli 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 6.2,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...