The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Web Design
> CSS Help
|
CSS Layout - filling a container div with divs
Discuss CSS Layout - filling a container div with divs in the CSS Help forum on Dev Shed. CSS Layout - filling a container div with divs Cascading Style Sheets (CSS) forum discussing all levels of CSS, including CSS1, CSS2 and CSS Positioning. CSS provides a robust way of applying standardized design concepts to your web pages.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

August 6th, 2003, 06:58 AM
|
|
Diagonal Man
|
|
Join Date: Sep 2001
Location: On your monitor
Posts: 210
Time spent in forums: 5 h 33 m 47 sec
Reputation Power: 12
|
|
|
CSS Layout - filling a container div with divs
Hi all,
I'm excruciatingly close to completing a three column CSS layout, in fact I have. But I have a problem..
I have one container div, containing 3 other divs, all floated left so they stack up next to each other, this works great (the container div is a fixed width). However, I want to have a solid background colour in the container div but this won't work. The container div is effectively 'empty' as it only contains the three other divs. The 3 divs flow out of this container div, overflow:visible won't have any effect because it only relates to actual content within a div, not other divs.
If I put line breaks or other inline content in the container div, it stretches down accordingly, but as I want the container div to automatically "envelope" the three inside divs automatically, I'm at a loss.
Can anyone help here? relative and absolute positioning the divs within the container doesn't work either.
|

August 6th, 2003, 08:12 AM
|
|
:: cerebralshock ::
|
|
Join Date: Aug 2002
Location: Everywhere & nowhere.
Posts: 133
Time spent in forums: 44 m 49 sec
Reputation Power: 11
|
|
|
<div id="container" style="background-color: bgcolor;">
<div id="1">blah1</div>
<div id="2">blah2</div>
<div id="3">blah3</div>
</div>
|

August 6th, 2003, 09:50 AM
|
|
Diagonal Man
|
|
Join Date: Sep 2001
Location: On your monitor
Posts: 210
Time spent in forums: 5 h 33 m 47 sec
Reputation Power: 12
|
|
|
That won't work, if you try it. The divs 'drop out' the bottom of the container.
The solution, it seems, is height: auto, followed by a box model hack that specifies min-height: <value> for CSS2 compliant browsers.
.centercontent {
height: 520px;
}
html>body .centercontent {
height: auto;
min-height: 520px;
}
|

August 6th, 2003, 02:19 PM
|
 |
mod_dev_shed
|
|
Join Date: Sep 2002
Location: Atlanta, GA
|
|
If you float all the <div>s you'll get the desired effect.
Code:
<div style="float:left:background-color:red">
<div style="clear:left;float:left;">X</div>
<div style="clear:left;float:left;">Y</div>
<div style="clear:left;float:left;">Z</div>
</div>
__________________
# Jeremy
Explain your problem instead of asking how to do what you decided was the solution.
|

August 6th, 2003, 02:32 PM
|
|
Diagonal Man
|
|
Join Date: Sep 2001
Location: On your monitor
Posts: 210
Time spent in forums: 5 h 33 m 47 sec
Reputation Power: 12
|
|
|
I just tried that, and the divs sit on top of one another, not next to each other...
|

August 6th, 2003, 02:34 PM
|
 |
mod_dev_shed
|
|
Join Date: Sep 2002
Location: Atlanta, GA
|
|
Sorry, I didn't read your entire post so I missed that part. Just don't clear the last two. The key is that the container must also float.
Code:
<div style="float:left:background-color:red">
<div style="clear:left;float:left;">X</div>
<div style="float:left;">Y</div>
<div style="float:left;">Z</div>
</div>
|

August 6th, 2003, 02:58 PM
|
|
Diagonal Man
|
|
Join Date: Sep 2001
Location: On your monitor
Posts: 210
Time spent in forums: 5 h 33 m 47 sec
Reputation Power: 12
|
|
|
Ah! Excellent!
Many thanks!
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|