4. Borders, margins, padding and Co.

In XSL-FO there are several concepts for the positioning of contents in blocks and for the generation of paddings, borders, indents and margins. These concepts can often be used alternatively. In this chapter the different possibilities and their correlations are introduced and also some recommendations for practice are made since the imprudent application of the concepts may be a big source of errors.

In the following graphic some concepts suitable for the positioning of contents in a block are illustrated:

Borders and paddings

Borders and paddings

("Inhalt" means content, "Bereich" means region.)

4.1. Margins

Margins which are generated by margin attributes are the most common form for generating paddings. The paddings refer to the areas between the region boundaries (print space limit) and the blocks contained therein as well as the areas between blocks.

The five possible attributes for margins are:

  • margin-top (top)

  • margin-bottom (bottom)

  • margin-left (left)

  • margin-right (right)

  • margin (top, bottom, left and right)

The formatter places the margins for blocks according to the following rules:

  • If no margins are specified, the block extends to the width of the print space. Successive blocks are layered one under the other with no spaces between them. This rule applies because in XSL-FO the default value is set to 0pt for all margins.

  • If a margin with a positive value is specified for the left and right side, the block is indented accordingly on the left and right side.

  • If a margin with a positive value is specified on the top or bottom, a corresponding area is formed over or under the block. A possibly following block will be shifted downwards.

  • The values of margins are not inherited, which means subordinated blocks do not adopt the values of superordinated blocks.

  • Subordinated blocks always emanate from the margins of the superordinated block.

  • Negative values for margins on the left and right side may lead to an exceedance of the print space limits. Negative values for the top and the bottom are ignored and should therefore not be set.

Example:

<fo:block margin-left="20mm">                          (1)
   INHALT INHALT  INHALT INHALT INHALT INHALT INHALT
   <!-- en: CONTENT CONTENT CONTENT CONTENT ... -->
   <fo:block margin-left="20mm">                       (2)
      INHALT INHALT INHALT INHALT INHALT INHALT INHALT
   </fo:block>
</fo:block>
<fo:block margin-top="20mm" margin-left="-10mm">       (3)
   INHALT INHALT INHALT INHALT INHALT INHALT INHALT
</fo:block>

(1) The margin-left attribute generates a margin to the left print space limit. Consequently, the content is indented by 20mm.

(2) Since this block is a child element of the first block, the initial point is the left margin of the parent block being moved to the right by 20mm. Additionally there is a 20mm margin, so that the block is indented by a total of 40mm from the print space margin.

(3) This block has a margin at the top. So a padding to the top block is generated. The negative value of margin-left effects that the block is extended by 10mm to the left and that the block begins beyond the left print space limit.

Formatter view

Formatter view - margins

4.2. Paddings

 

With the help of the padding attributes, paddings can be determined which range from the block limits to the inside. The block is extended accordingly by the padding attribute values.

The padding attributes are:

  • padding-start (writing direction lr-tb – the one being common for European languages: left)

  • padding-end (writing direction lr-tb: right)

  • padding-left (left)

  • padding-right (right)

  • padding-before (writing direction lr-tb: top)

  • padding-after (writing direction lr-tb: bottom)

  • padding-top (top)

  • padding-bottom (bottom)

  • padding (short form for top, right, bottom and left)

The formatter implements the padding attribute values for blocks according to the following rules:

  • If there are margins on the left and right side, the padding emanates from the margins.

  • If there are no margins on the left and right side, the block is also extended beyond the left and right print space limits accordingly.

  • padding on the top or bottom leads to an appropriate distance to the preceding or the following block. Here, padding should not be used but rather margin or space.

  • padding to the print space limit does not lead to an indent of the content but to an extension of the block beyond the print space.

  • The values for padding are not inherited, which means subordinated blocks do not adopt the values of superordinated blocks.

  • Negative values for padding are ignored.

Example:

<fo:block padding="10mm 10mm 10mm 10mm">                (1)
   INHALT INHALT INHALT INHALT INHALT INHALT INHALT 
   <fo:block padding="10mm 10mm 10mm 10mm">             (2)
      INHALT INHALT INHALT INHALT INHALT INHALT INHALT                         
   </fo:block>                                          (2)
</fo:block>                         
<fo:block padding="10mm 10mm 10mm 10mm">                (3)
   INHALT INHALT INHALT INHALT INHALT INHALT INHALT
</fo:block>

 

Formatter view

Formatter view - paddings

(1) The padding attribute generates a padding to the top and bottom to the next block. In this example a padding to the third block is generated because the second is within the block limits of the first block. The padding spaces to the left and to the right do not lead to an indentation of the content because they encounter the print space limits.

(2) The padding attribute generates a space to the top and bottom block. The padding spaces to the left and right do not lead to an indentation of the content because, here too, they encounter the print space limits.

(3) The padding attribute generates a padding to the top block. The padding is 30mm because in this example the paddings of the two blocks on the top encounter the padding of the bottom block and are added up.

In practice the padding is often used for micro-typographical details. Here an example follows (the page numbers of this book):

...
<fo:block line-height="6pt" text-align="left" border-start-style="solid" 
border-before-style="solid" border-before-width="1pt" border-start-width="1pt" margin-top="10.7mm" margin-bottom="0.7mm">            (1)                        
   <fo:block padding-top="0.7mm" padding-left="1mm">     (2)                        
      <fo:page-number/>
   </fo:block>
</fo:block>
...

(1) This external block is used for the positioning of the content block which contains a block with the page numbers. Also the visible border (border-start-style="solid" border-before-style="solid") and its line width (border-before-width="1pt" border-start-width="1pt") is determined at this position.

(2) The inner block contains the automatically generated page numbers and the information regarding the padding to the border. Similarly, it would be possible to omit this inner block and to specify the paddings in the external block. The specification of the inner block with its padding attributes gives a better overview.

Page number in the header

Page number in the header

 

4.3. Borders

Borders enclose blocks and are specified with the border attributes. According to their width the borders add an area outside the block they enclose.

For the determination of the borders in the four directions, the following four attributes are available. They are indicated according to the writing direction from left to right and from top to bottom.

  • border-before (top)

  • border-after (bottom)

  • border-start (left)

  • border-end (right)

Through further specifications these borders in their basic form can be determined individually when displayed. Specifications are:

  • color (colour of the border)

  • style (style of the border; valid values are for example solid (solid line or area), double (double line) or dotted (dotted line)

  • width (width of the line or border)

Example:

<fo:block border-style="solid" border-width="1mm" margin-bottom="10mm" padding="12mm 12mm 12mm 12mm"> (1) 
   INHALT INHALT INHALT INHALT INHALT INHALT INHALT 
   <fo:block border-style="solid" border-width="1mm" padding="10mm 10mm 10mm 10mm"> (2)
      INHALT INHALT INHALT INHALT INHALT INHALT INHALT 
   </fo:block>                         
</fo:block>
<fo:block border-style="solid" border-width="1mm"> (3)
   INHALT INHALT INHALT INHALT INHALT INHALT INHALT 
</fo:block> 

(1) The border-style attribute with the value solid generates a border with a solid line around the block. The line width is determined by the border-width attribute. The border encloses the content of both blocks at a distance of 12mm measured from the inner margin of the border, because in this example a padding was defined and the block contains another one. The margin-bottom attribute generates a distance of 10mm to the following third block.

(2) This block is nested in the first ones and also surrounded by them.

(3) Since this block has no padding space, the generated border lies directly on the boundary to the content.

Formatter view

Formatter view - borders

The following image shows the line styles which are generated by the style attribute.

Border lines

Border lines

Some stylesheet examples for borders:

...
<fo:block text-align="center"                         
 border-before-style="solid" border-before-width="5mm"             (1)
 border-after-style="double" border-after-width="3mm"              (2)           
 border-start-style="dotted" border-start-width="1mm"              (3)
 border-end-style="dashed" border-end-width="1mm">                 (4)
 Einheitliche Farbe, verschiedene Linienbreiten und verschiedene Linienarten
 <!-- en: Uniform colour, different line widths and different line types -->
</fo:block>                         
<fo:blocktext-align="center"                         
 border-width="2mm" border-style="solid"                           (5)
 border-before-color="grey" border-after-color="red" 
 border-start-color="blue" border-end-color="green">               (6)
 Verschiedene Farben, einheitliche Linienbreite und einheitliche Linienart
 <!-- en: Different colours, uniform line width and uniform line type -->
</fo:block>
...
 

(1) The attribute value solid generates a solid line and in this example it is located at the top margin (before) of the block.

(2) The attribute value double generates a double line at the bottom margin.

(3) The value dotted generates a dotted line at the left margin.

(4) The value dashed generates a dashed line at the right margin.

(5) The attributes border-width, border-style and border-color can be used if all border parts of the block shall look the same.

(6) With the color supplement a colour is specified which differs from the basic colour.

Formatter view

Formatter view - border lines

The formatter implements the border attribute values for blocks according to the following rules:

  • If there are margins on the left and right side, the external border limit emanates from the margins.

  • If there are no margins on the left and right side, the border is extended beyond the left and right print space limits accordingly.

  • border on the top and bottom leads to an appropriate distance from the preceding or the following block.

  • The values for border are not inherited, which means subordinated blocks do not adopt the values of superordinated blocks.

  • Negative values for border are ignored.

 

 

4.4. Spaces (vertical feeds)

The space attributes provide a range of possibilities for a more precise specification of vertical spaces (feeds) between blocks. With the help of the margin attribute, a space to the following block can also be generated, but the margins are only added up if a value margin-bottom is specified for a preceding block and a value margin-top is specified for a following block. However, with the space attributes the spaces of successive blocks can be controlled more varied and more precisely.

The following supplements are available for the attributes space-after and space-before:

  • space-after.precedence or space-before.precedence (feed-after, feed-before – preferred value).

  • space-after.conditionality or space-before.conditionality (conditional feed for page breaks).

  • space-after.optimum or space-before.optimum (optimal feed – when specifying feed tolerances for an automated vertical wedge).

  • space-after.minimum or space-before.minimum (minimal feed).

  • space-after.maximum or space-before.maximum (maximal feed).

The .precedence supplement determines which specification is preferably (with priority) selected for the feed when after and before values encounter each other. The size of the feed is determined by the attribute values in space-after and space-before or in .optimum, .minimum, .maximum.

With the .conditionality supplement the behaviour of two related feed specifications for page breaks (space-after in the preceding block, space-before in the following block) can be determined by the two possible attribute values discard and retain. If the .conditionality supplement is not used, the default value discard applies. With the help of this value, the block on the new page always begins at the top print space margin when doing a page break. But in the case of retain the space to the top print space margin is maintained on the new page.

Simple example:

<fo:block space-after="20mm" border-style="solid" border-color="#0033CC" border-width="5mm" font-size="30pt">   (1)
   INHALT INHALT INHALT INHALT INHALT INHALT INHALT                         
</fo:block>
<fo:blockspace-before="20mm" padding="5mm 5mm 5mm 5mm" border-style="solid" border-color="#0033CC" border-width="5mm" font-size="30pt"> (1)
   INHALT INHALT INHALT INHALT INHALT INHALT INHALT 
</fo:block>

 

Formatter view

Formatter view - spaces

(1) The attributes space-after and space-before generate a space between both blocks. Since they are not added up, the space is 20mm, and the result is equivalent to the one of the previous example, where a margin of 20mm was generated with the help of the margin-bottom attribute.

Here, a further complex example in order to illustrate the effect of feeds:

...
<fo:block text-align="center" border-width="2pt" border-style="solid"
 space-after.precedence="force" space-after="10mm">                    (1)
   Block mit höchster Priorität
   <!-- en: Block with top priority -->
</fo:block>
<fo:block text-align="center" border-width="2pt" border-style="solid"
 space-before="10000mm" space-before.precedence="5"                    (1)
 space-after="10mm" space-after.precedence="5">                        (2)
   space-before wird nicht berücksichtigt, space-after wird berücksichtigt
   <!-- en: space-before is not considered, space-after is considered -->
</fo:block>
<fo:block text-align="center" border-width="2pt" border-style="solid"                         
 space-before="10000mm" space-before.precedence="4"                    (3)                        
 space-after="20mm">
   space-before wird nicht berücksichtigt
   <!-- en: space-before is not considered -->
</fo:block>
<fo:block text-align="center" border-width="2pt" border-style="solid" space-before="10mm"> (3)
   Bei gleicher Priorität wird der größere Abstand übernommen
   <!-- en: When having the same priority, the greater space is adopted -->
</fo:block>                         
...

(1) Since the value force is the highest possible value for the space-after.precedence attribute, the space-after space is maintained and the space-before space in the second block is ignored.

(2) In this case higher priority determines the use of the feed. Since the space-after.precedence is greater than the space-before.precedence of the following block, the space-after space of the first block is processed.

(3) Here, no explicit information regarding priority is provided. As a consequence, both priorities have the value "0" and are equal. The specification of the greater space of both neighbouring blocks is used, in this example the space-after feed of the top block.

Formatter view

Formatter view

<< back next >>

Copyright © dpunkt.verlag GmbH 2004
Printing of the online version is permitted exclusively for private use. Otherwise this chapter from the book "XSL-FO in der Praxis" ("XSL-FO in practice") is subject to the same provisions as those applicable for the hardcover edition: The work including all its components is protected by copyright. All rights reserved, including reproduction, translation, microfilming as well as storage and processing in electronic systems.

dpunkt.verlag GmbH, Ringstraße 19B, 69115 Heidelberg, fon 06221-14830, fax 06221-148399, hallo@dpunkt.de