Padding and margins

Reply

Join Date: Feb 2002
Posts: 12,056
Reputation: cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light 
Solved Threads: 127
Administrator
Staff Writer
cscgal's Avatar
cscgal cscgal is online now Online
The Queen of DaniWeb

Padding and margins

 
0
  #1
Apr 8th, 2005
With regards to cellpadding and cellspacing for tables, and padding and margins for div tags, are they included or excluded in the height and width of a table cell or element?

For example, suppose I have an image of size 100x200 that I would like to enclose in a fixed width div tag with 5px of padding. Must I set the height and width of the div tag to 110x210 to accomidate?
Dani the Computer Science Gal
Follow my Twitter feed! twitter.com/DaniWeb
And if you're interested in Internet marketing there is twitter.com/DaniWebAds
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 303
Reputation: Patate is an unknown quantity at this point 
Solved Threads: 0
Patate's Avatar
Patate Patate is offline Offline
Posting Whiz

Re: Padding and margins

 
1
  #2
Apr 8th, 2005
I'm pretty sure that putting 5px of padding will not change the size of the image. If you set the size of the image to 100x200, the image itself will stay at 100x200 but it will take 110x210 because of the 5px on each sides.
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 764
Reputation: DaveSW is on a distinguished road 
Solved Threads: 17
DaveSW's Avatar
DaveSW DaveSW is offline Offline
Master Poster

Re: Padding and margins

 
0
  #3
Apr 8th, 2005
If I read your query correctly, it's the box model problem.
As I remember it, Mozilla takes the width and adds padding and margins, whilst IE takes the width and subtracts padding and margins...
So the answer is yes and no. lol
I believe some people use a strict doctype and the problem doesn't occur.
I just nest two divs, one with the width and one with margins/padding.

I haven't tested it, but I believe patate is correct that an image shouldn't change size when you add margins...
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 303
Reputation: Patate is an unknown quantity at this point 
Solved Threads: 0
Patate's Avatar
Patate Patate is offline Offline
Posting Whiz

Re: Padding and margins

 
0
  #4
Apr 8th, 2005
I don't know about Mozilla but IE adds it. The image doesn't change size. It just adds the padding around the image and the size of the div changes. But that's with IE, I'm not sure about Mozilla...
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 764
Reputation: DaveSW is on a distinguished road 
Solved Threads: 17
DaveSW's Avatar
DaveSW DaveSW is offline Offline
Master Poster

Re: Padding and margins

 
1
  #5
Apr 8th, 2005
It appears that for a div, IE in standards mode (with a strict or transitional doctype) adds padding and margins to the width.
In quirks mode, without a doctype or with an incomplete doctype, it subtracts them.

Mozilla adds them all the time.

I don't think this is the same for IE5 though. Maybe I'll test it out later.
Try testing this page with and without a doctype:

[HTML]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Test page</title>
<style type="text/css">
<!--
#first {
border: 1px solid #000;
width: 200px;
}
#second {
border: 1px solid #000;
padding: 50px;
width: 200px;
}
-->
</style>
</head>
<body>
<div id="first">&nbsp;</div>
<div id="second">&nbsp;</div>
</body>
</html>[/HTML]

This means that for an image in IE in quirks mode, padding is simply ignored.
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 303
Reputation: Patate is an unknown quantity at this point 
Solved Threads: 0
Patate's Avatar
Patate Patate is offline Offline
Posting Whiz

Re: Padding and margins

 
0
  #6
Apr 8th, 2005
This makes sense. I was testing with a doctype in EI6 btw.
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 764
Reputation: DaveSW is on a distinguished road 
Solved Threads: 17
DaveSW's Avatar
DaveSW DaveSW is offline Offline
Master Poster

Re: Padding and margins

 
0
  #7
Apr 8th, 2005
IE 5.x always subtracts padding, regardless of doctype.

It doesn't support padding for images, like 6 in quirks mode.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the HTML and CSS Forum
Thread Tools Search this Thread



Tag cloud for HTML and CSS
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC