W3C home > Mailing lists > Public > xsl-editors@w3.org > April to June 2003

Margin Issues (response to Comments 20 and 37)

From: Paul Grosso <pgrosso@arbortext.com>
Date: Mon, 19 May 2003 11:48:43 -0500
Message-Id: <>
To: xsl-editors@w3.org
Cc: werner.donne@re.be, eliot@isogen.com

The following is the answer to two XSL-FO related comments posted
to the xsl-editors mailing list.

Comment 20: Margins and Block Geometry
See [1] where the commentor (Eliot) asks several questions about
margins and blocks. In particular:

>It would also be helpful if 5.3.2 at least provided some motivation for
>the inclusion of margin properties or at least say why they have the
>counter-intuitive effect of pulling the border and padding rectangles
>outside of the content rectangles of their blocks' containing reference

The properties 'margin-left' and 'margin-right' were included in XSL for three reasons: (1) some of the namespaces that we would like to embed in XSL-FO, such as SVG and MathML, use CSS properties for styling and it is desirable to have a definition of these properties so that the embedded objects can access them from the context of the embedding. (2) the margin properties give a relative way to set indents from the containing block (as distinct from the 'indent' properties which are absolute values from the nearest reference area. And, (3) the Advisory Committee of the W3C took the position that the properties used in formatting should be consistent across all presentation namespaces wherever possible. Since the XSL committee wanted to allow indenting with respect to the reference area, using the 'indent' properties, then it became important to define the relationship between these two ways of specifying indents.

For simplicity, let us assume a 'lr-tb' 'writing-mode'. In XSL (and CSS) the margins are outside the borders which are outside the padding which is outside the content rectangle. The sum of the margins, border-widths, padding and content rectangle width must equal the width of the content rectangle of the containing block. The indents, however, are to the edges of the content rectangle and the border-widths and padding are outside that content rectangle. In both approaches, the border (and padding) may encroach outside the content rectangle of the  containing block: when the margin values are negative (which are explicitly allowed) or when the indents are insufficient to keep the borders and padding within the content rectangle of the containing block. The point here is not that one should use the capability, but that the behavior of both approaches is the same. The difference is only in the point of reference used for the computations.

Since these two constructs both influence the position of the content rectangle (and by extension the padding and border rectangles),  it was necessary to define how these two properties interact. This relationship is specified in section 5.3.2 of the XSL specification.

In quick summary (assuming a 'lr' writing-mode):

Margin, being a relative distance, is not an inherited value.. Therefore, the initial value is the value  that is used when the property is not explicitly specified . The initial specified value for 'margin-left' is '0'  By the rules given in section 5.3.2, this value is perfectly consistent with the unchanged inherited value of 'start-indent' which is an inherited property. So if neither property is explicitly specified then the resulting information is self consistent.

The rules of 5.3.2 are written so that if 'margin-left' is explicitly specified, then it overrides any explicit specification of 'start-indent'. and the computed value of 'start-indent' is determined from the computed value of 'margin-left'. The computed value of 'margin-left' is pretty straightforward for all the possible values except 'auto'.

Now consider what happens when 'margin-left' is given the specified value of 'auto' . This is a case where the XSL 1.0 specification is not as clear is it might be. The property description for 'margin-left', section 7.10.3, has the following sentence for the description of the 'auto' value:
  "See the CSS2 section on computing widths and margins for behavior."

This is a direct quote of the CSS2 REC from section 8.3. In the CSS2 REC, the phrase "computing widths and margins " is linked to  section 10.3 Computing widths and margins which is the intended reference. This is not as clear in the XSL REC. This section has various subsections on 'inline', 'block', 'floats' and 'absolutely positioned' elements for both the non-replace (text) case and the replaced (images, SVG) case. Consider, for example, the case of a non-replaced block.. There are a number of factors that influence the determination of the computed value of 'margin-left' in this case:
  1.  whether the specified value of  the 'inline-progression-dimension' (or 'width')
       of that block element is a numeric value or expression or 'auto',
  2.  whether  the specified value of  'margin-right' is 'auto',
  3.  whether the inline-progression-direction of the containing block is 'lr' or 'rl',

If the specified value of the 'inline-progression-dimension'  (or 'width') is 'auto' then 'margin-left' is set to '0pt' by rule.

Let BR-width be the width of the border rectangle. The border rectangle of a block contains the padding rectangle and the content rectangle so the BR-width is the sum of the following:
   BR-width = border-left-width + padding-left + width + padding-right + border-right-width

If 'width' has a numeric specification (not the value 'auto'), then BR-width has a well determined numeric computed value using the formula immediately above because the border-wdith and padding properties can only have numeric values ('auto' is not an option).

Therefore, if 'margin-right' has a numeric value (not 'auto'), then the computed value of 'margin-left' is determined by the formua:
  margin-left = width of content rectangle of containing block -( BR-width + margin-right)

If both 'margin-left' and 'margin-right' have the value 'auto', then
  margin-left = margin-right = 1/2*(width of content rectangle of containing block - BR-width)

Thus, setting both 'margin-left' and 'margin-right' to 'auto' is a quick way to center the border rectangle in the content rectangle of the containing block. This could be viewed as another reason for including the margin properties in XSL.

If 'margin-left' is not explictly specified and 'start-indent' is, then the computed value of 'margin-indent' is computed using the formulae in section 5.3.2 of the XSL REC.

>Comment 37:  Deviation margin-left and margin-right from CSS [1]
>The margin-left and margin-right properties are taken over from CSS. However, they
>don't completely behave as in CSS. More specifically the value "auto" is treated
>differently. Section 5.1.2 states that for auto values the formulas must be applied.
>In this case it would be the last two formulas of section 5.3.2. As a consequence,
>it is the same as if margin-left or margin-right were absent. The auto value is not
>treated as an explicit value. In my opinion it should be and it should be computed
>according to the CSS rules, from which the properties are taken over, even if that
>implies an exception to the indentation rules. I see no point in being only partially
>compatible with CSS properties.
>A practical consequence, for example, is that a fixed-width block which is stacked
>in another block can't be centered through setting the margin-left and margin-right
>properties to "auto", such as it is the case in CSS. The same goes for aligning the
>stacked block to the left or right.

Given the above discussion, we do not see the problem. We do not believe that 'auto' is treated differently from CSS. We do, however, see the need to clarify the specification so that it can be correctly read without recourse to the explanation above. We propose to adopt the following editorial changes:

1. Restore the link to Section 10.3 on the phrase, "computing widths and margins" that occurs in the description of the 'auto' values in the 'margin-top', 'margin-bottom', 'margin-left' and 'margin-right' properties.

2.  In the second paragraph following the second Note in section 5.3.2, change

    If the corresponding absolute "margin" property is specified on the
   formatting object and the formatting object generates a reference
   area the computed value of the margin is used to calculate the computed
   value of the corresponding "Y-indent" property, where Y is either "start"
   or "end". The formulae for "start-indent" and "end-indent" are":

    If the corresponding absolute "margin" property is specified on the
   formatting object and the formatting object generates a reference
   area the computed value of the margin is used to calculate the computed
   value of the corresponding "Y-indent" property, where Y is either "start"
   or "end". The computed value of the of the absolute "margin" property is
   determined by the CSS descriptions of the properties and the relevant
   sections (in particular section 10.3) of the CSS Recommendation referenced
   by these properties. The formulae for "start-indent" and "end-indent" are":

[1] http://www.w3.org/Style/XSL/Group/2002/10/FO-comments#02OctDec-0046
[2] http://www.w3.org/Style/XSL/Group/2002/10/FO-comments#03JanMar-0013
Received on Monday, 19 May 2003 12:58:51 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 20:44:22 UTC