Re: margin vs. padding

"Charles F. Munat" wrote:
> 
> >> is there any preference for one of them on the Body tag in CSS ??
> > I think padding makes more sense, but I don't know what's preferred.
> 
> That depends on whether you consider the "body" to encompass the entire
> window. Currently, that is always the case, but what if a web page were
> inserted into another page (say, an SVG page)? Then the margins might make
> more sense.

Yes.

> Actually, both make sense even now, but you wouldn't know that from the way
> body is implemented. What would make the most sense would be this:
> 
> body { background: red; margin: 10px; padding: 10px; }
> 
> Assuming the browsers default background color is white, 

Why do you assume that and what CSS would you write in the UA stylesheet to
make it so?

> there should be a
> 10px white band around the page. The body content would then sit 10px
> further inside the red area. Make sense?

Not when the root element is html, no.

> I tested this in Opera, IE, and Netscape and none of them showed a white
> border. Evidently, body is identified with the window itself. I don't see
> any reason it must be...

http://www.w3.org/TR/REC-CSS2/colors.html#q2
  The background of the box generated by the root element covers 
  the entire canvas.
  For HTML documents, however, we recommend that authors specify 
  the background for the BODY element rather than the HTML 
  element. User agents should observe the following precedence 
  rules to fill in the background: if the value of the 
  'background' property for the HTML element is different 
  from 'transparent' then use it, else use the value of the 
  'background' property for the BODY element. If the resulting 
  value is 'transparent', the rendering is undefined. 

-- 
Chris

Received on Thursday, 18 January 2001 06:55:15 UTC