Re: Properties of HTML style

Chris Ridd writes:
 > 
 > I'm slightly confused about where I should be setting properties which
 > are global to an entire HTML file, and precisely which ones are
 > inherited by other elements.
 > 
 > For instance, if I wanted to have a global 6em left margin, what would
 > the effects be of setting this in either HTML or BODY? As I read the
 > spec, setting it on BODY would make every subsequent element inherit the
 > margin, thus paragraphs would have a margin of 12em (6 for the inherited
 > margin, 6 for the body's margin) - effectively the stylesheet becoming
 > (after inheritence):
 > 
 > BODY { margin-left: 6em; }
 > P { margin-left: 6em; }

This is incorrect.

The margin properties are among the ones that are *not*
inherited. Every element has a margin of zero, unless explicitly set
in the style sheet.

*But*: the margins are relative, i.e., they are counted starting from
the parent's margin. If the window is 20cm wide and you set a margin
on the BODY of 2cm on each side, the children of BODY will think the
window is only 16cm wide. The diagram in section 4 of the CSS1 spec[1]
is meant to show how elements nest inside each other.

Thus, if you want a global margin of 6em, all you have to do is set

    BODY {margin-left: 6em}

and leave all the other margins alone. The child elements will by
default have a zero margin and they will be placed inside the parent's
margins.

 > 
 > It isn't clear from the spec what I should expect when setting the
 > margin on the HTML tag.

The difference between HTML and BODY in this respect is one of
personal preference. You can set the global margin either on HTML or
on BODY, since there is only one of each, and every other element is
inside both of them. The CSS1 draft arbitrarily recommends using BODY,
so that style sheets from different authors have a better chance of
cascading well.


Bert

[1] http://www.w3.org/pub/WWW/TR/WD-css1-960505.html#formatting-model

-- 
  Bert Bos                                ( W 3 C ) http://www.w3.org/
  http://www.w3.org/pub/WWW/People/Bos/                      INRIA/W3C
  bert@w3.org                             2004 Rt des Lucioles / BP 93
  +33 93 65 77 71                 06902 Sophia Antipolis Cedex, France

Received on Monday, 22 July 1996 08:15:51 UTC