Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > floats and collapsing divs

Reply
Thread Tools

floats and collapsing divs

 
 
JL
Guest
Posts: n/a
 
      09-13-2007
Hi

Suppose I have a footer div with a background colour and, in the footer,
I'd like to have some links on the left and a copyright notice on the
right. I'd do something like this:

#footer {
color: #FFF;
background-color: #000;
padding: 4px 10px;
}

<div id="footer">
<div style="float: left">
<a href="#">Privacy Policy</a> | <a href="#">Site Map</a>
</div>
<div style="float: right">
Copyright &copy 2007 MyComp
</div>
</div>

However, if I do this, the black background of the footer div
disappears. I know this is because the floated contents do not prop up
the footer container.

The only workarounds I know are to give #footer a height, which ruins
things when fonts are resized, or putting an element inside the footer,
after the other two div's, that is clear:both; but neither option is
satisfactory.

Am I missing something here? What do you guys do?
 
Reply With Quote
 
 
 
 
Ben C
Guest
Posts: n/a
 
      09-13-2007
On 2007-09-13, JL <> wrote:
> Hi
>
> Suppose I have a footer div with a background colour and, in the footer,
> I'd like to have some links on the left and a copyright notice on the
> right. I'd do something like this:
>
> #footer {
> color: #FFF;
> background-color: #000;
> padding: 4px 10px;
> }
>
><div id="footer">
> <div style="float: left">
> <a href="#">Privacy Policy</a> | <a href="#">Site Map</a>
> </div>
> <div style="float: right">
> Copyright &copy 2007 MyComp
> </div>
></div>
>
> However, if I do this, the black background of the footer div
> disappears. I know this is because the floated contents do not prop up
> the footer container.
>
> The only workarounds I know are to give #footer a height, which ruins
> things when fonts are resized, or putting an element inside the footer,
> after the other two div's, that is clear:both; but neither option is
> satisfactory.


Those are both good ways, although not without their drawbacks as you
say.

> Am I missing something here? What do you guys do?


You can make the footer overflow:hidden.

Not because you care about what happens when it overflows but to make it
start a new block formatting context, and block formatting context roots
_do_ grow in height to fit floats in.
 
Reply With Quote
 
 
 
 
dorayme
Guest
Posts: n/a
 
      09-13-2007
In article <>,
JL <> wrote:

> The only workarounds I know are to give #footer a height, which ruins
> things when fonts are resized,


Even when given in em?

--
dorayme
 
Reply With Quote
 
JL
Guest
Posts: n/a
 
      09-15-2007
Ben C wrote:
> On 2007-09-13, JL <> wrote:
>> Hi
>>
>> Suppose I have a footer div with a background colour and, in the footer,
>> I'd like to have some links on the left and a copyright notice on the
>> right. I'd do something like this:
>>
>> #footer {
>> color: #FFF;
>> background-color: #000;
>> padding: 4px 10px;
>> }
>>
>> <div id="footer">
>> <div style="float: left">
>> <a href="#">Privacy Policy</a> | <a href="#">Site Map</a>
>> </div>
>> <div style="float: right">
>> Copyright &copy 2007 MyComp
>> </div>
>> </div>
>>
>> However, if I do this, the black background of the footer div
>> disappears. I know this is because the floated contents do not prop up
>> the footer container.
>>
>> The only workarounds I know are to give #footer a height, which ruins
>> things when fonts are resized, or putting an element inside the footer,
>> after the other two div's, that is clear:both; but neither option is
>> satisfactory.

>
> Those are both good ways, although not without their drawbacks as you
> say.
>
>> Am I missing something here? What do you guys do?

>
> You can make the footer overflow:hidden.
>
> Not because you care about what happens when it overflows but to make it
> start a new block formatting context, and block formatting context roots
> _do_ grow in height to fit floats in.


Works nicely in FF but not IE6. Is there a way to get this to work in IE6?
 
Reply With Quote
 
JL
Guest
Posts: n/a
 
      09-15-2007
dorayme wrote:
> In article <>,
> JL <> wrote:
>
>> The only workarounds I know are to give #footer a height, which ruins
>> things when fonts are resized,

>
> Even when given in em?


No! Funnily enough I'd never thought of that.

I've tried this with height: 1.5em; but the text is vertically aligned
to the top of the container div. How do I vertically align the text in
the middle of the container?
 
Reply With Quote
 
BootNic
Guest
Posts: n/a
 
      09-15-2007
JL <> wrote: news::

[snip]
>>>
>>> #footer {
>>> color: #FFF;
>>> background-color: #000;
>>> padding: 4px 10px; }
>>>
>>> <div id="footer">
>>> <div style="float: left">
>>> <a href="#">Privacy Policy</a> | <a href="#">Site Map</a> </div>
>>> <div style="float: right">
>>> Copyright &copy 2007 MyComp </div> </div>
>>>
>>> However, if I do this, the black background of the footer div
>>> disappears. I know this is because the floated contents do not prop
>>> up the footer container.

[snip]
>> You can make the footer overflow:hidden.
>>
>> Not because you care about what happens when it overflows but to make
>> it start a new block formatting context, and block formatting context
>> roots _do_ grow in height to fit floats in.

>
> Works nicely in FF but not IE6. Is there a way to get this to work in
> IE6?


<!--[if lt IE 7]>
<style type="text/css">
#footer {
height:0;
overflow:visible;
}
</style>
<![endif]-->

--
BootNic Saturday September 15, 2007 9:56 AM
They always say time changes things, but you actually have to change
them yourself.
*Andy Warhol*
 
Reply With Quote
 
Bergamot
Guest
Posts: n/a
 
      09-15-2007
JL wrote:
> Ben C wrote:
>>
>> You can make the footer overflow:hidden.
>>
>> Not because you care about what happens when it overflows but to make it
>> start a new block formatting context, and block formatting context roots
>> _do_ grow in height to fit floats in.

>
> Works nicely in FF but not IE6. Is there a way to get this to work in IE6?


add property

zoom: 1;

It's an IE proprietary property that other browsers ignore, but does
absolute wonders for pretty much all versions of IE.

--
Berg
 
Reply With Quote
 
dorayme
Guest
Posts: n/a
 
      09-15-2007
In article <>,
JL <> wrote:

> dorayme wrote:
> > In article <>,
> > JL <> wrote:
> >
> >> The only workarounds I know are to give #footer a height, which ruins
> >> things when fonts are resized,

> >
> > Even when given in em?

>
> No! Funnily enough I'd never thought of that.


Try it, it worked well enough on your page, I gave it 1.5em. It
is simple at least.

--
dorayme
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
When using collapsing/expanding DIVs in IE6 container does not expand. Chris K. HTML 4 06-04-2008 03:23 PM
Problems with margins, paddings, divs and floats! PLEASE HELP! Agix HTML 7 05-10-2007 10:38 PM
Managing divs within divs.... rich HTML 0 02-02-2006 07:38 PM
Floats to chars and chars to floats Kosio C Programming 44 09-23-2005 09:49 AM
collapsing space between hidden divs D. Alvarado Javascript 1 09-04-2004 02:25 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57