XP> Margins, borders, padding, and backgrounds

From: Grant, Melinda (melinda.grant@hp.com)
Date: Wed Sep 20 2006 - 16:48:59 EDT

  • Next message: don@lexmark.com: "Re: XP> [CSS Print]"

    From HP's perspective (and I think we're not alone), the CSS
    specification is difficult to interpret with respect to how margins,
    borders, padding, and backgrounds work when applied to the <body> and
    <html> elements. Recently we have learned that the CSS3 Paged Media
    module is not clear on how the same properties used within an @page
    context should interact with the html properties.
     
    I'd like to share my new-and-improved understanding based on discussions
    within the CSS WG: ;-)

    * First, there are html attributes and there are css properties.
    In html, the body element has a bgcolor attribute, but the html element
    does not. For XHTML documents, the UA (printer) must convert the body
    bgcolor attribute into an equivalent printer style rule:
            So <body bgcolor="red"> gets converted into the printer
    stylesheet rule: body {background-color: red}. (This gets a bit more
    complicated for HTML documents, but we don't need to go there.) This
    printer stylesheet rule will be overridden by an author stylesheet rule,
    should one exist. See
    http://www.w3.org/Style/Group/css2-src/cascade.html#q13.
    * The body element is no different when it comes to CSS styling
    from any other element. Backgrounds, margins etc behave just as they do
    for a div, for example.
    * The html element is the root element. It can also be selected
    with ':root'. It is special, in that a background is applied to the
    margins as well as the content area. This is because it 'paints the
    canvas', which is infinite. The only way in XHTML to put a background
    in the html margin area and/or the body margin area is to use a
    background on the html element. (See
    http://www.w3.org/TR/CSS21/colors.html#q2.)
    * The attached file, 'margin-both.xhtml' when opened with Firefox,
    provides an example of how html and body edgings should be rendered.

    There are still some open questions about how @page properties work. I
    am hoping to publish a new version within the next week or so that will
    resolve questions such as the following: [My proposed answers are in
    brackets.]

    * Is a font property set within an @page rule applied to the page
    content area (unless overridden by properties set on elements rendered
    on the page), or just to the contents of the page margin boxes?
    [Proposed Answer: Just to the margin boxes.]
    * Do the html and page margins collapse? [no]
    * Are html and body borders closed at the bottom of each page, or
    just at the end of the document? [Just at the end of the document]
    * Does a background property set within an @page rule get applied
    to the page margins? [Yes] To the page area unless obscured by html,
    body, or other backgrounds? [????, under discussion]
    * On the last page of a document, do the html and body properties
    terminate immediately after the last content, or at the bottom of the
    page (e.g., do the html and body margins get drawn right below the last
    paragraph, or at the bottom of the page? [Immediately after content.]
    * Similarly, on the last page, do the page bg, border, etc. extend
    to the bottom of the page, or terminate after the last content? [bottom
    of the page]
    * Others?

    Best regards,
     
    Melinda

      _____

    HP - Melinda Grant
    Connectivity Standards
    Consumer Printing and Imaging
    +1 (541) 582-3681
    melinda.grant@hp.com
      _____

     


    attached mail follows:


    Hello Melinda,

    > So is there any difference in XHTML between setting attributes on the
    > body versus the html elements?

    Do you mean attributes or properties?

    The <html> element doesn't have a bgcolor attribute, only <body> does.
    And in XHTML1, the bgcolor attribute is still supposed to work the same
    way as in HTML. (But CSS says that the way it works is subtly
    different: In HTML documents, bgcolor="red" is equivalent to 'body
    {background-color: red}' in the user style sheet, except that it has
    specificity=0. In XHTML documents, it is up to the UA to analyze the
    document and construct an appropriate UA style sheet, e.g., with 'html
    {background-color: red}'. See section 6.4.4:
    http://www.w3.org/Style/Group/css2-src/cascade.html#q13)

    As for CSS properties, there is absolutely nothing special about the
    <body> element in XHTML. Setting 'body {background: red}' is no
    different from 'div {background: red}', i.e., only the box of the body
    itself is red.

    The <html> element is the root element, so it is still special. And thus
    the only way in XHTML to set the background of the canvas is with 'html
    {background:...}'

    That is, unless...

    >
    > (I'm still trying to figure out how body and html attributes should
    > relate to @page attributes...)

    ... if we allow a 'background' property inside '@page', it presumably
    causes a background to be rendered behind the background of the <html>
    element, if any.

    Bert

    -- 
      Bert Bos                                ( W 3 C ) http://www.w3.org/
      http://www.w3.org/people/bos                               W3C/ERCIM
      bert@w3.org                             2004 Rt des Lucioles / BP 93
      +33 (0)4 92 38 76 92            06902 Sophia Antipolis Cedex, France
    




    This archive was generated by hypermail 2.1.4 : Wed Sep 20 2006 - 16:49:06 EDT