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

Padding problem in Firefox

I use to trust Firefox, but in this case, I don't know what to think. My
test page:

http://gusgus.cn/test/index.html

IE6 does the right thing. The containting <div> is 600px, and within it,
there's one <div> of 400px and another of 200px, laying side by side.
The right <div> has padding on the left and right, to add some space
within the box, but Firefox (0.9.2) seem to confuse paddings as margins.
Here's the right <div> in my CSS:

#right {
float: right;
width: 200px;
overflow: hidden;
background-color: #DDDDFF; /* blue */
text-align: left;
padding: 8px 8px 8px 8px;
}

This box in Firefox is not 200 wide, but 216 (width + padding). It must
be a bug, or my understanding of margins and padding will crumble.

Gustaf
Jul 20 '05 #1
5 28831
Gustaf Liljegren wrote:
I use to trust Firefox, but in this case, I don't know what to think. My
test page:

http://gusgus.cn/test/index.html

IE6 does the right thing. The containting <div> is 600px, and within it,
there's one <div> of 400px and another of 200px, laying side by side.
The right <div> has padding on the left and right, to add some space
within the box, but Firefox (0.9.2) seem to confuse paddings as margins.
Here's the right <div> in my CSS:

#right {
float: right;
width: 200px;
overflow: hidden;
background-color: #DDDDFF; /* blue */
text-align: left;
padding: 8px 8px 8px 8px;
}

This box in Firefox is not 200 wide, but 216 (width + padding). It must
be a bug, or my understanding of margins and padding will crumble.


Firefox is right. IE6 shows it wrong, but only because you are
triggering quirks mode. See
<http://gutfeldt.ch/matthias/articles/doctypeswitch.html> for details on
quirks and standard mode.

And see
<http://msdn.microsoft.com/workshop/author/css/overview/cssenhancements.asp>
for Microsoft's explanation of the differences, particularly
<http://msdn.microsoft.com/library/en-us/dnie60/html/cssenhancements.asp?frame=true#cssenhancements_top ic3>,
"Fix the Box Instead of Thinking Outside It"

If you remove the <?xml version="1.0" encoding="utf-8"?> line, you'll
trigger standard mode in IE6 and it will show the page the same way as
Firefox.
Matthias

Jul 20 '05 #2
Gustaf Liljegren <gu*****@algonet.se> wrote:
I use to trust Firefox, but in this case, I don't know what to think. My
test page:

http://gusgus.cn/test/index.html

IE6 does the right thing. The containting <div> is 600px, and within it,
there's one <div> of 400px and another of 200px, laying side by side.
The right <div> has padding on the left and right, to add some space
within the box, but Firefox (0.9.2) seem to confuse paddings as margins.
Here's the right <div> in my CSS:

#right {
float: right;
width: 200px;
overflow: hidden;
background-color: #DDDDFF; /* blue */
text-align: left;
padding: 8px 8px 8px 8px;
}

This box in Firefox is not 200 wide, but 216 (width + padding). It must
be a bug, or my understanding of margins and padding will crumble.


Width 200px + left padding 8px + right padding 8px = 216px.
FireFox is right.

IE6 would also be right if you triggered Standards mode, at present
you trigger quirks mode and so it emulates the bugs in IE5 and puts
the padding inside the width. IE6 has a big whereby it triggers quirks
mode upon encountering the xml declaration before the doctype. Ditch
that and it will behave like FireFox (and Opera).

Steve

--
"My theories appal you, my heresies outrage you,
I never answer letters and you don't like my tie." - The Doctor

Steve Pugh <st***@pugh.net> <http://steve.pugh.net/>
Jul 20 '05 #3
Gustaf Liljegren wrote:
I use to trust Firefox, but in this case, I don't know what to think. My
test page:

http://gusgus.cn/test/index.html This box in Firefox is not 200 wide, but 216 (width + padding). It must
be a bug, or my understanding of margins and padding will crumble.


No, Firefox is doing it correctly, it should be 216px. As Matthias
already said, you're triggerring quirks mode in IE, which explians why
it's using the buggy, IE5/Win box-model. (See Tantek's box model hack [1]

The problem is that the full width of a box is calculated by:
(L = Left, R = Right, M = Margin, B = Border, P = Padding)

LM + LB + LP + Width + RP + RB + RM

So, your box width's are:

* #container:
LM + LB + LP + Width + RP + RB + RM
0 0 0 600px 0 0 0 = 600px

* #left:
LM + LB + LP + Width + RP + RB + RM
0 + 0 + 0 + 400px + 0 + 0 + 0 = 400px

* #right:
LM + LB + LP + Width + RP + RB + RM
0 + 0 + 8px + 200px + 8px + 0 + 0 = 216px

So, your #left + #right = 616px, which is wider than #container, so
there is no room for Firefox to fit #right where you want it to. The
easiest fix will be to reduce widht of #left and #right by a total of
16px, and everything should fit nicely. it works best if you set:

#right { width: 384px }
[1] http://www.tantek.com/CSS/Examples/boxmodelhack.html

--
Lachlan Hunt
http://www.lachy.id.au/

Please direct all spam to ab***@127.0.0.1
Thank you.
Jul 20 '05 #4
On Mon, 09 Aug 2004 16:20:03 +0200, Gustaf Liljegren
<gu*****@algonet.se> wrote:
http://gusgus.cn/test/index.html

IE6 does the right thing...
No it's not, provided that I have understood your question correct.
Here's the right <div> in my CSS:

#right {
float: right;
width: 200px;
overflow: hidden;
background-color: #DDDDFF; /* blue */
text-align: left;
padding: 8px 8px 8px 8px;
}

This box in Firefox is not 200 wide, but 216...
...a bug, or my understanding of margins and padding
will crumble.


The total outside width of a <div> box is the sum of the values for the
following properties...

margin-left
+ border-left-width
+ padding-left
+ width
+ padding-right
+ border-right-width
+ margin-right
= total occupied width of any {display:block} type box

So your "understanding of margins and padding" needs to be updated :-)

Most especially; the 'width' property suggests a width for the box
content only, all the other properties are added on the outside of that
inner content width.

<http://www.w3.org/TR/CSS1#block-level-elements>

--
Rex
Jul 20 '05 #5
Thanks a lot to everyone who help me with this question. Now I
understand what widths and heights really are.

But I can't help thinking IE had a good idea. The standard compliant way
means that everytime you use a little border or padding, you also need
to subtract the same amounts from the widths and heights = more fiddling
before you get it right.

Anyway, I'm glad to understand now.

Gustaf
Jul 20 '05 #6

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

Similar topics

2
by: StarQuake | last post by:
At this site: http://forwarding.robas.com You can see in IE there is cell padding in 'Berkman Bedrijven' and with Firefox there isn't. I don't want any cell padding. Anyone? --...
1
by: books1999 | last post by:
Hi there, I have a problem with this css/div and i cannot work it out. I would like either container to be able to push the background box to grow but in Firefox it overflows. Can someone find a...
36
by: phil-news-nospam | last post by:
Here is a simpler (no drop shadows) example of the padding bug I see: http://phil.ipal.org/usenet/ciwas/2006-05-08/buttons-1.html So far I find nothing in the CSS2 document that says I should...
2
by: cbjewelz | last post by:
Hey all. So I'm having problems with cross browser alignments. I'm looking at Safari and Mozilla Firefox. I develop in Safari and so it looks perfect there however in Firefox my vertical...
3
by: autospanker | last post by:
Ladies and Gentleman, I have been having this problem that has been driving me insane. I have a website that when viewed in Firefox first, the content in the body area is pushed down. Then when...
0
by: Bouzy | last post by:
I have a problem that I know gets asked about a lot. Its how my page differs in IE vrs. Firefox. I know IE sucks, but hears whats going on. IE......
2
by: pammyspammy | last post by:
Hi - Some background info: I'm helping to redesign an internal website at work, and I've decided to use CSS, though I don't really have any experience with it. I figure now's a good time to...
1
by: littlealex | last post by:
IE6 not displaying text correctly - IE 7 & Firefox 3 are fine! Need some help with this as fairly new to CSS! In IE6 the text for the following page doesn't display properly - rather than being...
3
by: Steve | last post by:
Hi All I have an asp.net 2.0 website with the following css file It uses Master pages and in Firefox 3.04 for windows only, 3 of the web pages don't display the Master page properly The...
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: 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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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,...

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.