473,386 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

background of containing block doesn't extend to child floating blocks

Hi,

For the code below, only "aaa" has a red background but "bbb" and
"ccc" don't have it:

<div style="background: red">aaa
<div style="float:left">bbb</div>
<div style="float:left">ccc</div>
</div>

In order for the red background to extend to "bbb" and "ccc", I have
to make "aaa" a float too:

<div style="background: red; float:left">aaa
<div style="float:left">bbb</div>
<div style="float:left">ccc</div>
</div>

This behavior exists in both IE 7 and FF 2.0. Any idea why it is so? I
can't find any support for
this behavior in the CSS spec. Any help is much appreciated!

Thanks!

Jun 2 '07 #1
3 4242
On 2007-06-02, ke**@cpttm.org.mo <ke**@cpttm.org.mowrote:
Hi,

For the code below, only "aaa" has a red background but "bbb" and
"ccc" don't have it:

<div style="background: red">aaa
<div style="float:left">bbb</div>
<div style="float:left">ccc</div>
</div>

In order for the red background to extend to "bbb" and "ccc", I have
to make "aaa" a float too:

<div style="background: red; float:left">aaa
<div style="float:left">bbb</div>
<div style="float:left">ccc</div>
</div>

This behavior exists in both IE 7 and FF 2.0. Any idea why it is so? I
can't find any support for
this behavior in the CSS spec. Any help is much appreciated!
In both examples, the inner divs have transparent backgrounds (the
default). In the second example, the containing div extends in height to
fit the floats in, and you can therefore see its red background through
the transparent backgrounds of the two inner divs.

In the first example the height of the container is zero, which is why
you don't see any red. It still has a red background in principle, but
zero area.

A float grows to fit the floats inside because it's a "block formatting
context root". This is in the CSS 2.1 spec, but you have to look quite
closely to find it.

See 9.4.1 "Floats [...] establish new block formatting contexts" and
then 10.6.7 "'Auto' heights for block formatting context roots [..] if
the element has any floating descendants whose bottom margin edge is
below the bottom, then the height is increased to include those edges."
Jun 2 '07 #2
On Jun 3, 2:31 am, Ben C <spams...@spam.eggswrote:
A float grows to fit the floats inside because it's a "block formatting
context root". This is in the CSS 2.1 spec, but you have to look quite
closely to find it.

See 9.4.1 "Floats [...] establish new block formatting contexts" and
then 10.6.7 "'Auto' heights for block formatting context roots [..] if
the element has any floating descendants whose bottom margin edge is
below the bottom, then the height is increased to include those edges."
Hi Ben,

Thanks a lot for your explanation! It has been very helpful! Basically
what it
means is that if a paragraph contains a floating tall image, the
height of
that paragraph does NOT take into account that of the image, so that
the
image could "stick into" the next paragraph. However, if the first
paragraph is
a float itself, it will be moved around so its height should include
that of the
image.

Jun 3 '07 #3
On 2007-06-03, ke**@cpttm.org.mo <ke**@cpttm.org.mowrote:
On Jun 3, 2:31 am, Ben C <spams...@spam.eggswrote:
>A float grows to fit the floats inside because it's a "block formatting
context root". This is in the CSS 2.1 spec, but you have to look quite
closely to find it.

See 9.4.1 "Floats [...] establish new block formatting contexts" and
then 10.6.7 "'Auto' heights for block formatting context roots [..] if
the element has any floating descendants whose bottom margin edge is
below the bottom, then the height is increased to include those edges."

Hi Ben,

Thanks a lot for your explanation! It has been very helpful! Basically
what it means is that if a paragraph contains a floating tall image,
the height of that paragraph does NOT take into account that of the
image, so that the image could "stick into" the next paragraph.
However, if the first paragraph is a float itself, it will be moved
around so its height should include that of the image.
You got it.
Jun 3 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
181
by: Tom Anderson | last post by:
Comrades, During our current discussion of the fate of functional constructs in python, someone brought up Guido's bull on the matter: http://www.artima.com/weblogs/viewpost.jsp?thread=98196 ...
19
by: Jerry | last post by:
Hi Folks, Ok, here's my story. I was asked to create a website for the church I attend. I am a complete newbie to creating websites. So, I did the usual -- did a bunch of googling, found...
5
by: Alfonso Morra | last post by:
I have the following data types: typedef union { long l ; double f; char* s ; void* p ; } Value ; typedef struct {
10
by: Cool Guy | last post by:
Consider: void Start() { if (!TryToDoSomething()) ShowErrorMessage(); }
26
by: Bill Norton | last post by:
If you wrap one division around another like this: <div id="wrapper"> <div id="child">...</div> </div> ....the wrapper division will be considered the containing block of the child division...
6
by: foolmelon | last post by:
If a childThread is in the middle of a catch block and handling an exception caught, the main thread calls childThread.Abort(). At that time a ThreadAbortException is thrown in the childThread. ...
11
by: Gérard Talbot | last post by:
Hello, <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <title></title> <style type="text/css"> body {background-color: white; color: black;}...
19
by: david.karr | last post by:
If in my CSS I set the "background-color" property on the "body" element, it only covers the background of the elements defined in the body, up to the current width and height of the page. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.