473,397 Members | 1,969 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,397 software developers and data experts.

Float and margin issues

Here's the test page:

<!doctype html public "-//w3c//dtd xhtml 1.0 strict//en"
"http://www.w3.org/tr/xhtml1/dtd/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>Test</title>
<style type="text/css">
#Wrapper
{
width: 750px;
border: 10px solid black;
background-color: Purple;
}

#Content
{
margin: 15px 30px 0px 30px;
border: 5px solid Blue;
background-color: White;
border: 5px solid Blue;
width: 660px;
}

#FloatLeft
{
background-color: Yellow;
border: 5px solid Red;
margin-top: 25px;
float: left;
width: 320px;
}

#FloatRight
{
background-color: Yellow;
border: 5px solid Green;
margin-top: 25px;
float: right;
width: 320px;
}

#Footer
{
margin-top: 50px;
background-color: White;
border: 5px solid Blue;
width: 740px;
}
</style>

</head>
<body>
<div id="Wrapper">
<div id="Content">Content
<div id="FloatLeft">FloatLeft</div>
<div id="FloatRight">FloatRight</div>
</div>
<div id="Footer">Footer</div>
</div>
</body>
</html>

On Windows, IE6, Opera 7.2, and Mozilla Firebird 0.7 all render this
slightly different. The layout I'm trying to achieve is the way its
rendered in IE6. Which browser gets this correct, and how might I achieve
the desired layout in all three browsers?
Jul 20 '05 #1
5 4535
Mike Irwin wrote:

On Windows, IE6, Opera 7.2, and Mozilla Firebird 0.7 all render this
slightly different. The layout I'm trying to achieve is the way its
rendered in IE6. Which browser gets this correct, and how might I achieve
the desired layout in all three browsers?


Well, according to CSS 2.1 (see
http://www.w3.org/TR/CSS21/visudet.h...eight-property, paragraph
10.6.3), floated elements should not be taken into account when
calculating the height of a block-level element.

This means that your div#Content has just the height of its textual
content, #FloatLeft and #FloatRight are out of the normal flow, that's
why they appear outside of the #Content in Firebird... and in CSS
2.1-compliant browsers. (Yes, IE6 is wrong again).

A solution you might want to use in your fixed-size example would be to
explicitly set the height property on the #Content, for example:
div#Content { height: 60px ; }

Jul 20 '05 #2
"Vincent" <vincent.@.fr> wrote in message
news:bm**********@news-reader2.wanadoo.fr...
Well, according to CSS 2.1 (see
http://www.w3.org/TR/CSS21/visudet.h...eight-property, paragraph
10.6.3), floated elements should not be taken into account when
calculating the height of a block-level element.

This means that your div#Content has just the height of its textual
content, #FloatLeft and #FloatRight are out of the normal flow, that's
why they appear outside of the #Content in Firebird... and in CSS
2.1-compliant browsers. (Yes, IE6 is wrong again).

A solution you might want to use in your fixed-size example would be to
explicitly set the height property on the #Content, for example:
div#Content { height: 60px ; }


It's not really the height that matters to me, but the fact that the two
floated divs ignore the margin-top value in #Footer. According to my
understanding, and maybe I'm reading
http://www.w3.org/TR/CSS2/box.html#collapsing-margins wrong, but it says
that "Vertical margins between a floated box and any other box do not
collapse." Opera and IE both add the margin, but Firebird does not.
Jul 20 '05 #3

"Mike Irwin" <mi**@faroutfreakyshit.com> wrote in message
news:Zo****************@bignews3.bellsouth.net...
"Vincent" <vincent.@.fr> wrote in message
news:bm**********@news-reader2.wanadoo.fr...
Well, according to CSS 2.1 (see
http://www.w3.org/TR/CSS21/visudet.h...eight-property, paragraph
10.6.3), floated elements should not be taken into account when
calculating the height of a block-level element.

This means that your div#Content has just the height of its textual
content, #FloatLeft and #FloatRight are out of the normal flow, that's
why they appear outside of the #Content in Firebird... and in CSS
2.1-compliant browsers. (Yes, IE6 is wrong again).

A solution you might want to use in your fixed-size example would be to
explicitly set the height property on the #Content, for example:
div#Content { height: 60px ; }


It's not really the height that matters to me, but the fact that the two
floated divs ignore the margin-top value in #Footer. According to my
understanding, and maybe I'm reading
http://www.w3.org/TR/CSS2/box.html#collapsing-margins wrong, but it says
that "Vertical margins between a floated box and any other box do not
collapse." Opera and IE both add the margin, but Firebird does not.


IE and Opera are interpreting the declarations wrongly.

Floated elements are taken out of the flow but relative to the containing
element, and the containing element only.

The flowed elements are the content div and the footer div. The distance
drawn between them should be 50px as declared by #Footer.

To suggest the IE6/Opera display, remove the margin-top rule on the floated
elements and put the floated elements in a div with margin-top:25px nested
in the content div.

Louise

Jul 20 '05 #4
"boclair" <bo*****@bigpond.net.au> wrote in message
news:bm************@ID-210679.news.uni-berlin.de...
IE and Opera are interpreting the declarations wrongly.

Floated elements are taken out of the flow but relative to the containing
element, and the containing element only.

The flowed elements are the content div and the footer div. The distance
drawn between them should be 50px as declared by #Footer.

To suggest the IE6/Opera display, remove the margin-top rule on the floated elements and put the floated elements in a div with margin-top:25px nested
in the content div.


OK, at least I know who's to blame now. I've wrapped the floating divs in
another div which sets the margins I want, and although the margins aren't
quite the same in any of the browsers I'm testing with, it'll work for now.

Thanks for the help.
Jul 20 '05 #5

"Mike Irwin" <mi**@faroutfreakyshit.com> wrote in message
news:qH*****************@bignews3.bellsouth.net...
"boclair" <bo*****@bigpond.net.au> wrote in message
news:bm************@ID-210679.news.uni-berlin.de...
IE and Opera are interpreting the declarations wrongly.

Floated elements are taken out of the flow but relative to the containing element, and the containing element only.

The flowed elements are the content div and the footer div. The distance drawn between them should be 50px as declared by #Footer.

To suggest the IE6/Opera display, remove the margin-top rule on the floated
elements and put the floated elements in a div with margin-top:25px nested in the content div.


OK, at least I know who's to blame now. I've wrapped the floating divs in
another div which sets the margins I want, and although the margins aren't
quite the same in any of the browsers I'm testing with, it'll work for

now.
Thanks for the help.

Hi Mike
If you put an empty div after the two floated divs, and nest it inside the
content div, then the content div will contain the two floated divs and the
top margin on the footer div will be OK

<div id="Wrapper">
<div id="Content">Content
<div id="FloatLeft">FloatLeft</div>
<div id="FloatRight">FloatRight</div>
<div style="clear: both;"></div>
</div>

HTH
David
Jul 20 '05 #6

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

Similar topics

2
by: jon slinn | last post by:
Does anybody know why I can't get a simple two col design to work using the following css? At the moment my columns seem to be arranging left and right correctly but are stacked on top of each...
1
by: trialanderror | last post by:
I've been happily chugging along thinking I understood floating divs and now find that I know a lot less than I thought I did. And the more I try "fixing" things, the worse it gets. A lot of what...
4
by: Chris Sharman | last post by:
I've a very simple page (intranet, but moved to http://services.ccagroup.co.uk/dtest.html for you - so the links are all broken). essentially it's just a list of links. I've split it into two...
0
by: jonipony | last post by:
HELP: Float Left box is drifting to the right in ie! -------------------------- I need som HELP with my CSS coding! On the following web page my design falls apart at screen size 800 x 600...
2
by: krsgoss | last post by:
I'm trying to do a two column "form" layout based on article here: http://www.alistapart.com/stories/practicalcss/ The idea is to have a label, and a value using definition list markup. I...
3
by: hantechs | last post by:
<html> <body> <p style="width:30%;">text1</p> <p style="float:left;">text2</p> </body> </html> The effect of this html code is : text1 and text2 each is on a line. My question is: Why text2...
0
by: idealer | last post by:
I am just transitioning to div based layout and love it so far... I am having a few quirks with IE that I can use some help with. SAMPLE: http://arenamotorgroup.com/index_comp.html In IE...
27
by: GloStix | last post by:
WARNING VIDEO TAKES A WHILE TO LOAD http://screencast.com/t/BWQ6DNtsM I really don't know how to fix this other than putting another div. But I dont' exactly want to do that for every page....
4
by: smartic | last post by:
hi i'm having problem with designing css layout i'm not expert so i need any one good in css help me in this page, my problem in this page i need to make menus to be displayed in one line beside each...
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
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.