Welcome Guest!
Please login
If you do not have an account yet on The Web Squeeze forums, please Register! It’s FREE and there are many benefits:
- Receive Fast Advice
- Learn Programming Languages
- Get Professional Website Reviews
- Quick Troubleshooting Assistance
|
|
A Div With Floating Boxes Inside It Loses Its Height
This is a discussion on A Div With Floating Boxes Inside It Loses Its Height, within the CSS section. This forum and the thread "A Div With Floating Boxes Inside It Loses Its Height" are both part of the Designing Your Website category.
![]() ![]() |
Nov 16 2008, 06:00 AM
Post
#1
|
|
![]() Rapid Squeezer ![]() ![]() ![]() ![]() Posts: 146 Joined: 3-July 08 |
This is a recurring issue for me. Positioning divs. Honestly I'm quite intelligent and good at learning new things... I don't know what it is about CSS that continues to confuse me.
Say you have a <div like so <div class="wrapper"> <div class="leftColumn"> </div> <div class="rightColumn"> </div> </div> Their css looks like so CODE .rightColumn { float: right; } .leftColumn { float: left; } .wrapper { clear: both; } I have a clear: both because I repeat this chunk of html, e.g <div class="wrapper" /> <div class="wrapper" /> <div class="wrapper" /> What I'm trying to work out is, once you position 2 columns using this method, they hope up out of the wrapper div and it no longer actually wraps around them. What I mean by that is if you put a background color on the wrapper class, regardless of how high the left or right column is, the wrapper is not affected. If you have a look at the following image, you see the above theory applied. There is a little rounded corner class being applied to the wrapper wit a yellow background. It should wrap around both the left and right column but it doesn't.
mmm.jpg ( 24.27K )
Number of downloads: 4Whats the gap in my css knowledge? |
|
|
Nov 16 2008, 06:15 AM
Post
#2
|
|
![]() Squeeze Machine ![]() Posts: 508 Joined: 7-October 08 From: Australia |
The gap is that you need to apply the same logic as you apply to your wrapper. Try this:
CODE <div class="wrapper"> <div class="leftColumn"> </div> <div class="rightColumn"> </div> <div class="clear"></div> </div> CODE .clear { clear: both; } You need a "clearing" div as the last div in your wrapper. Just to clear the floats, I make a class for it, as you'll need to use it all over the place -------------------- The more you visit, the more I'll post: http://japheththomson.com/
|
|
|
Nov 16 2008, 06:24 AM
Post
#3
|
|
![]() Rapid Squeezer ![]() ![]() ![]() ![]() Posts: 146 Joined: 3-July 08 |
Wow. Thats all. It worked. Seems weird to me that it works but then again thats how I feel about most css.
Thanks heaps man. |
|
|
Nov 16 2008, 07:42 AM
Post
#4
|
|
![]() Squeeze Machine ![]() Posts: 508 Joined: 7-October 08 From: Australia |
My pleasure!
I'd explain in more detail why it works, but to be honest, I don't know the detail. I just know it works! It seems that because you've floated items, they're essentially "floating" in the top of the div, and so you need to clear both the left and right float before the div closes... well, that's my logic for it anyway -------------------- The more you visit, the more I'll post: http://japheththomson.com/
|
|
|
Nov 16 2008, 10:10 AM
Post
#5
|
|
![]() Rapid Squeezer ![]() ![]() ![]() ![]() Posts: 146 Joined: 3-July 08 |
lol. yeah thats how i think about it too.
I think it would be great if something could just be applied to the wrapper div to tell it to continue to hold size connectivity / stretching whatyamacallIt if the elements are floating but i'm not complaining. I just imagine something like CODE <div style="float-resize: true;"> <div id="col1"></div> <div id="col2"></div> </div> Would be so cool |
|
|
Nov 16 2008, 03:27 PM
Post
#6
|
|
|
Squeeze Machine ![]() Posts: 682 Joined: 15-February 08 From: UK |
I think it would be great if something could just be applied to the wrapper div to tell it to continue to hold size connectivity / stretching whatyamacallIt if the elements are floating but i'm not complaining. Try the css { overflow: auto; } on the parent float. Overflow auto/hidden can be useful sometimes, but in general I recommend a simple clearing <div> as the most bomb-proof solution, with no real drawbacks. |
|
|
Nov 16 2008, 07:06 PM
Post
#7
|
|
![]() Squeeze Machine ![]() Posts: 508 Joined: 7-October 08 From: Australia |
Hey, CSS-Tricks has a screencast which covers floats that might help you. In fact, it covers your exact issue at about 6:15 in the video. Well worth a look to help explain floats, Chris is great!
CSS-Tricks: All About Floats Screencast -------------------- The more you visit, the more I'll post: http://japheththomson.com/
|
|
|
Nov 16 2008, 10:57 PM
Post
#8
|
|
![]() Fresh Squeezed ![]() ![]() Posts: 31 Joined: 12-November 08 From: Racine, Wisconsin |
You can also add some fancier CSS to the last div in the markup that replaces the need for an extra empty div. However it's not as browser compatible. I don't recommend this method unless you're darn good with CSS, because it'll take some tweaking. I personally use the empty div most of the time anyway. Just showing another method.
CODE (element/class/ID):after {
content: " "; display: block; visibility: hidden; clear: both; height: 0.1px; font-size: 0.1em; line-height: 0; } This post has been edited by Aken: Nov 16 2008, 10:58 PM |
|
|
Nov 17 2008, 06:56 AM
Post
#9
|
|
![]() Rapid Squeezer ![]() Posts: 261 Joined: 27-August 08 From: London, UK |
CSS compatibility tables
There is a link to see what you can use in what browsers. I think the clear and clearfix methods are best for now, At least until everyone adopts IE8 (which by the way will have full CSS2 -------------------- Working @ On-idle - Technology by design.
|
|
|
If you found The Web Squeeze to be helpful, please donate so we can keep this site FREE, FRESH, and fortified with Web Design & Development info!
![]() ![]() |
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:
Similar Topics
| Topic Title | Replies | Topic Starter | Views | Last Action | |||
|---|---|---|---|---|---|---|---|
![]() |
6 | Jason | 371 | 21st February 2008 - 12:25 PM Last post by: thesealportalteam |
|||
![]() |
3 | Ryan | 148 | 2nd April 2008 - 11:51 PM Last post by: Rakuli |
|||
![]() |
13 | jackfranklin | 335 | 7th April 2008 - 01:44 PM Last post by: paintingtheweb |
|||
![]() |
2 | MikeHopley | 201 | 25th April 2008 - 09:14 AM Last post by: MikeHopley |
|||
![]() |
1 | Mark | 187 | 4th June 2008 - 01:24 PM Last post by: karinne |
|||






Nov 16 2008, 06:00 AM














