CSS Calculating box width
Posted: Thu Mar 30, 2006 4:41 pm
I'm looking for clarification here. I was under the impression that when calculating the width of a block element you add like this:
left margin + width + right margin = total width
I did not think padding was counted in this as it is inside the box. But I guess I am wrong as both Firefox and Safari tack on 5 pixels to the right of an 800 pixel wide block when I add padding-left = 5px.
No IE, on the other hand does not add padding. So it looks as I expect. But if I adjust the width to accomodate the padding to 795 pixel, then IE displays the block at a total of 795 pixels.
So I guess the box model I describe above is for IE? And standards compliant browser cacluate like so:
left margin + left padding + width + right padding + right margin = total width.
(Well, you have to add in borders too.)
left margin + width + right margin = total width
I did not think padding was counted in this as it is inside the box. But I guess I am wrong as both Firefox and Safari tack on 5 pixels to the right of an 800 pixel wide block when I add padding-left = 5px.
No IE, on the other hand does not add padding. So it looks as I expect. But if I adjust the width to accomodate the padding to 795 pixel, then IE displays the block at a total of 795 pixels.
So I guess the box model I describe above is for IE? And standards compliant browser cacluate like so:
left margin + left padding + width + right padding + right margin = total width.
(Well, you have to add in borders too.)