Forum Moderators: not2easy

Message Too Old, No Replies

Fluid two-column and avoid float?

or is there a way to catch a floated elements height?

         

davidbraun

9:48 am on Feb 18, 2005 (gmt 0)

10+ Year Member



Hello again

My other, real struggle is the following:
I try to trim-down a rather overstuffed CSS-oriented, fluid 2 column-design within a "drop-shadow box".

My (working but unelegant) approach today is that I nest the 2 columns in each another <div>, and format these (so I have to float only 1 object): A left, 25%-wide column, and a right, 75%-wide one, both containing <p>aragraphs, <img>, <ul>ists etc. The left column is basically an abstract ("at a glance") of the right column's content.

<div class="container"><div class="inhalt">

<div class="leftcolumn">
<p>left column</p>
more...
</div>
<div class="rightcolumn">
<p>right column</p>
much more...
</div>

</div>bottom border-stuff here</div>

So far so good, but I'd like to trim down the nesting, and am at the point where I have

<div class="container"><div class="inhalt">

<p>right column (quite long paragraphs in here)</p>
<p class="left">left column (abbr. only)</p>

</div>bottomstuff</div>

where the default <p>aragraphs float right, while the left-column <P> are "float: none"

I believe that I have to float the right-column-paragraphs because the left column elements are 25% wide and thus would sit 4 in a row, and here comes my problem: the floated elements height isn't catched and overflows the bottom if the left (unfloated) column isn't longer. So, best would be to completely avoid floats, or to know how to get the container to catch up with the height of the floated elements...

Or, would it be more "reasonable" to create a left-floated container which holds all the stuff (of the left column)?

Thanks very much for insight, hints, directions and whatever else: david: )

createErrorMsg

1:32 pm on Feb 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



know how to get the container to catch up with the height of the floated elements

Floats are removed from the flow, so other elements cannot interact with them (except in limited ways), including their containers. This means that the float cannot dictate the container's height. This is the proper implementation of the float property. (You may have noticed that IE displays this part of your design correctly? That's because IE ignores this part of the float specifications.) So it's not that you're triggering a bug or doing anything wrong. You just need a technique to change the normal behavior into something useful for your layout.

To get a container to wrap around it's floated children, you need to either (a)float the container or (b)add a clearing element [webmasterworld.com] to the bottom of the container.

float the right-column-paragraphs

This is an opinion, so take it for what it's worth, but I think you should avoid floating each individual paragraph. Wanting to cut down on nesting is a good goal, but not at the expense of complicating your layout in other ways. Float is one of those properties that seems to get more unstable the more it's used on a page. The rules are complex and not always intuitive and the more floats you add the harder it becomes to predict just what they will do. I'm not saying they're unstable or shouldn't be used -- floating is my layout property of choice -- but as with all things, moderation is key.

You are better off leaving the container div for the right column and just floating that, than you are floating every paragraph, img or other element on that side of the page. (One float VS Many floats).

cEM

davidbraun

2:09 pm on Feb 18, 2005 (gmt 0)

10+ Year Member



Hi createErrorMsg...

Thanks for clearing things/opinions up!

I already tampered around with floating the containers, but this didn't work, and things got quite weird ...
(no, I didn't try <body style="float: left"> ;^).

Also, "closing" the bottom with a <p style="clear: all"> didn't the trick, it got overflowed too (don't know why, though), so I too think it'll (sadly) be best to nest one of the two columns into a floating div, and then have the other paragraphs / elements run in the <div class="inhalt">

Or... is there another way to get "classed" objects (you know, <p class="left or right">, <ul ... > etc) to align next to each other?

Oh, and, concerning MSIE, no, I didn't see it ignoring this specific CSS-rule... I usually invest a painful lot of time trying to make my (standard-compliant, AFAIK) CSS work for this beast too, and so I'm tempted not to look at as long as possible...

createErrorMsg

3:42 pm on Feb 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<p style="clear: all">

The value options for the clear property are: none, left, right, and both [w3.org], indicating which sides of an element should not be allowed to sit adjacent to a floated box.

Try replacing "all" with "both."

cEM

davidbraun

3:52 pm on Feb 18, 2005 (gmt 0)

10+ Year Member



Of course. Silly of me... (must be a remnant of the pre-css era or something - gr)

thanks again!

davidbraun

4:28 pm on Feb 18, 2005 (gmt 0)

10+ Year Member



Update...

Actually, once this bug (clear: all) was removed, and after de-nesting the footer-part, it's all working, even the max-width AND min-width in Safari! Ha-HAA!

I feel like a happy camper, ready to meet the week-end (or try out other layout adventures)!

again, thanks many times!