By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,035 Members | 1,543 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,035 IT Pros & Developers. It's quick & easy.

CSS Bug in IE7

P: n/a
hi guy, pls help to test the following page...

//------------------------------------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh_TW"
lang="zh_TW" dir="ltr">
<head>
<style type="text/css">

body{

margin : 0px;
padding : 0px;
text-align : left;
background-color : green;
}

#page{

padding : 0px;
width : 900px;
margin-left : auto;
margin-right : auto;
}

#header{

padding : 0px;
margin : 0px;
height : 70px;
width : 100%;
background-color : red;
}

#main{

float : left;
background-color : yellow;
}

#main_a{

float : left;
width: 100%;
}

#main_a_content{

padding: 15px;
}
#footer{

width : 100%;
height : 40px;
background-color : #dedede;
}

.clear{ clear : both; }

</style>
</head>

<body id="body">

<div id="page">

<div id="header">
header...
</div>

<div id="main">

<div id="main_a">
<div id="main_a_content">

main...

</div>
</div>

<div class="clear"></div>

</div>

<div class="clear"></div>
<div id="footer">
footer...
</div>
</div>

</body>
</html>
//------------------------------------------------

the yellow color in the #main can't extend to full 100% width...

this problem only exist in IE7, but okay with

1. IE6
2. Firefox 1.5
3. Opera 9

any idea for this? maybe a new bug from IE?

thanks.

Nov 3 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Els
howa wrote:
hi guy, pls help to test the following page...
[snip code]
the yellow color in the #main can't extend to full 100% width...
Because you didn't give #main 100% width.
this problem only exist in IE7, but okay with

1. IE6
2. Firefox 1.5
3. Opera 9

any idea for this? maybe a new bug from IE?
IE7 is shrink-wrapping the float (just like other browsers btw), but
not extending the width because of a child that wants 100% width.
If you take out the 100% width of the #main_a div, the other browsers
will do the same as IE7.

I'm sure some W3C-specs-guru will know which behaviour is technically
correct, but personally I'm not worried about this discrepancy between
IE7 and the other browsers. Just set 100% width on #main if that's
what you want, don't rely on the children to set the width of the
parent.

--
Els http://locusmeus.com/
accessible web design: http://locusoptimus.com/
Nov 3 '06 #2

P: n/a

Els 寫道:
howa wrote:
hi guy, pls help to test the following page...

[snip code]
the yellow color in the #main can't extend to full 100% width...

Because you didn't give #main 100% width.
this problem only exist in IE7, but okay with

1. IE6
2. Firefox 1.5
3. Opera 9

any idea for this? maybe a new bug from IE?

IE7 is shrink-wrapping the float (just like other browsers btw), but
not extending the width because of a child that wants 100% width.
If you take out the 100% width of the #main_a div, the other browsers
will do the same as IE7.

I'm sure some W3C-specs-guru will know which behaviour is technically
correct, but personally I'm not worried about this discrepancy between
IE7 and the other browsers. Just set 100% width on #main if that's
what you want, don't rely on the children to set the width of the
parent.

--
Els http://locusmeus.com/
accessible web design: http://locusoptimus.com/
well, my concern is..

why FF, Opera & IE6 is full extending the width?

is that mean IE7 is the only correct browser in doing this (or others
are wrong)?

Nov 3 '06 #3

P: n/a
On 2006-11-03, howa <ho******@gmail.comwrote:
[snip]
why FF, Opera & IE6 is full extending the width?
Because 100% means "100% of the width of the containing block". The
containing block of #main_a is #main, and #main is an auto-width
normal-flow block box which means its computed width is the full content
width of its container, which is #page, which has a width set on it, of
900px.

So 100% means "100% of 900px" here, or 900px. And that's what you're
getting in Firefox.
is that mean IE7 is the only correct browser in doing this (or others
are wrong)?
No, IE7 is the only incorrect browser out of the three! Sounds like this
is actually a regression between IE6 and IE7.
Nov 3 '06 #4

P: n/a
Els
Ben C wrote:
On 2006-11-03, howa <ho******@gmail.comwrote:
[snip]
>why FF, Opera & IE6 is full extending the width?

Because 100% means "100% of the width of the containing block". The
containing block of #main_a is #main, and #main is an auto-width
normal-flow block box
Nope, it is floated, which means it would shrink-wrap in both Opera,
FF, IE6 and IE7 if it weren't for the content inside it being too
wide.
No, IE7 is the only incorrect browser out of the three! Sounds like this
is actually a regression between IE6 and IE7.
Where do the specs say that a floated shrink-wrapping box should
expand to 100% of its parent when it has a child that has a set width
of 100% but no content to fill up that width? (it is possible this is
written in the specs, but I haven't seen it afair)

--
Els http://locusmeus.com/
accessible web design: http://locusoptimus.com/
Nov 3 '06 #5

P: n/a
On 2006-11-03, Els <el*********@tiscali.nlwrote:
Ben C wrote:
>On 2006-11-03, howa <ho******@gmail.comwrote:
[snip]
>>why FF, Opera & IE6 is full extending the width?

Because 100% means "100% of the width of the containing block". The
containing block of #main_a is #main, and #main is an auto-width
normal-flow block box

Nope, it is floated, which means it would shrink-wrap in both Opera,
FF, IE6 and IE7 if it weren't for the content inside it being too
wide.
You are right, and I was wrong. As you point out I did not observe that
#main was floated.

What we have in the OP's example is

page
main
main_a

page is a normal-flow block box. main is floated, and main_a is floated
and 100% of the width of main.

But main is width: auto, and main is the containing block for main_a.

width: auto on a float (which main is) means shrink-to-fit. In other
words it depends on the content.

The spec says (in Appendix F, under the width property)

"If the containing block’s width depends on this element’s width, then
the resulting layout is undefined in CSS 2.1."
>No, IE7 is the only incorrect browser out of the three! Sounds like this
is actually a regression between IE6 and IE7.
No, that was rubbish. IE7 is well within the spec there. Actually I
think IE7 is doing what I think is the most sensible interpretation
(treat percentage width of shrink-to-fit container as auto since it's
makes no sense).

I have just tried this in Konqueror, and it's doing the same thing as
IE7.
Where do the specs say that a floated shrink-wrapping box should
expand to 100% of its parent when it has a child that has a set width
of 100% but no content to fill up that width? (it is possible this is
written in the specs, but I haven't seen it afair)
They don't. They explicitly leave it undefined.
Nov 3 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.