Forum Moderators: not2easy

Message Too Old, No Replies

only floating div inside container

         

warp_fr

2:59 pm on Sep 21, 2004 (gmt 0)

10+ Year Member



Is it correct having in a container, only a div float:left and a div float:right instead of a div without float with another div with either right or left float (with container and inside div having all fixed widh)?
Will I run in any particular problem?
I believe layout is the same, but it does make a difference as it make thing much easier in my project (no more ie doubling marge, 3px jog...).
The only problem I notice till now is if I set a background image for the container, it gets lost using the 2 floating div.

warp_fr

3:23 pm on Sep 21, 2004 (gmt 0)

10+ Year Member



ok, I find out about my background problem...
It's like finding a solution to a problem will just bring on another one dealing with CSS and browser compatibility.
Sorry for my newbie questions, I do search a lot before posting here, but sometimes, I just find my answer after it.
;-)

createErrorMsg

3:27 pm on Sep 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Having a float:left and a float:right nex to each other is fine, as long as you maintain tight, pixel-perfect control over the width of the container those floats are in. If the container is sized in EM or % (or if the container is the <body> tag itself), the layout will break when the container shrinks to less than the width of the two floats combined. The result will be that the float that comes second in the code will move below the float that comes first.

To avoid this, simply be sure to put those floats inside of a container box that has a width set in PX, equal to just slightly more than the combined width of the floats. Make sure to flaot this conatiner as well so that it encloses the two floats in all browsers.

warp_fr

5:04 pm on Sep 21, 2004 (gmt 0)

10+ Year Member



thx man.
Could you just clarify this :
"Make sure to float this container as well so that it encloses the two floats in all browsers."

I just tried it and it's great for at least 1 thing : my container background image now just flow all the way down till it reachs the longest div inside without using tricks at all and in both IE and Mozilla.

createErrorMsg

8:01 pm on Sep 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Could you just clarify this :
"Make sure to float this container as well so that it encloses the two floats in all browsers."

One of float's intended behaviors is to cause an element to ignore the borders of it's containing block and 'float' over them in a downward direction. This is great when used to float images amongst paragraphs, but not so great when you have two floats in a box and you need the box itself to be as tall as the longest thing in it. With two floats in a box, the size of the floats has no effect on the size of the container (b/c they're not in the flow). This means anything that follows the container in the source code (a footer, perhaps) will be overlapped by the floats.

To avoid this, you need to force the container box to expand and enclose those floats. IE browsers automatically do this (which is a mistake on their part), but compliant browsers follow the specs and don't. To make them do it, you need to apply a float value (and a width!) to the containing block, itself.

Another option is to apply a clear:both to the element (like a footer) that follows the container. However, if the container block itself has any styling (background color, background image, borders), these will not appear in compliant browsers because the container has no in-flow content. In this case, you must float the container.

my container background image now just flow all the way down till it reachs the longest div inside without using tricks at all and in both IE and Mozilla.

I'm not sure I understand what your describing here. Can you give some more details? Is what you describe what you want to have happen, or what is happening that you do not want?

warp_fr

9:08 pm on Sep 21, 2004 (gmt 0)

10+ Year Member



Yes, it is what I wanted to happen. It's exactly what you are saying about styling the container and make it floats so background image do showup in container.
Thanks a lot, things are way less confusing to me now.

createErrorMsg

9:33 pm on Sep 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Glad to help. :)