Absolute Positioning
Content can be positioned anywhere on the page by placing the content in a fo:block-container element and setting the absolute-position attribute. If the absolute-position attribute is set to "fixed", the content will then be positioned on the page relative to the page area which contains the fo:block-container element.
If the absolute-position attribute is set to "absolute", the content will be positioned on the page relative to the reference area which contains the fo:block-container element. The reference area is not the containing block, it is the containing fo:region, fo:table-cell, fo:block-container, fo:inline-container or fo:table-caption. In XSL-FO 1.0, the specification was ambiguous and the block-container was positioned relative to the containing area, but in XSL 1.1 this has been clarified to mean the containing reference area.
Positioning block-containers
It is important to realise that block-containers are not positioned relative to the containing block. Figure 17-1 shows FO with two absolutely positioned block containers. Both block-containers will be positioned relative to the containing region, because the region is the containing reference area. As they both have the same top attribute they will both be positioned in the same place.
<fo:flow flow-name="body">
<fo:block>
some text
<fo:block-container absolute-position="absolute" height="2cm" top="3cm">
<fo:block>
in block-container one
</fo:block>
</fo:block-container>
</fo:block>
<fo:block>
some more text
<fo:block-container absolute-position="absolute" height="2cm" top="3cm">
<fo:block>
in block-container two
</fo:block>
</fo:block-container>
</fo:block>
</fo:flow>
The simplest way to position a block-container is to place it inside another block-container which does not have the absolute-position attribute. FO for doing this is shown in Figure 17-2. The outer block-container is not absolutely positioned and will be placed in the normal flow of content. The inner block-container is absolutely positioned relative to the outer one.
<fo:flow flow-name="body">
<fo:block>
some text
<fo:block-container>
<fo:block-container absolute-position="absolute" height="2cm" top="3cm">
<fo:block>
in block-container one
</fo:block>
</fo:block-container>
</fo:block-container>
</fo:block>
<fo:block>
some more text
<fo:block-container>
<fo:block-container absolute-position="absolute" height="2cm" top="3cm">
<fo:block>
in block-container two
</fo:block>
</fo:block-container>
</fo:block-container>
</fo:block>
</fo:flow>
Positioning and sizing block containers
A block-container with absolute-position = "absolute" is positioned relative to its containing reference area.
The distance between the left edge of the block-container and the left edge of the containing reference area is set by the left attribute. This attribute specifies the offset of the block-container's left edge from the containing reference area's left edge. The default value is "0pt", which causes the two edges to be in the same place. Positive values of left move the left edge of the block-container to the right, making the block-container smaller.
The distance between the right edge of the block-container and the right edge of the containing reference area is set by the right attribute. This attribute specifies the offset of the block-container's right edge from the containing reference area's right edge. The default value is "0pt", which causes the two edges to be in the same place. Positive values of right move the right edge of the block-container to the left, making the block-container smaller.
The distance between the top edge of the block-container and the top edge of the containing reference area is set by the top attribute. This attribute specifies the offset of the block-container's top edge from the containing reference area's top edge. The default value is "0pt", which causes the two edges to be in the same place. Positive values of top move the top edge of the block-container downwards, making the block-container smaller.
The distance between the bottom edge of the block-container and the bottom edge of the containing reference area is set by the bottom attribute. This attribute specifies the offset of the block-container's bottom edge from the containing reference area's bottom edge. The default value is "0pt", which causes the two edges to be in the same place. Positive values of bottom move the bottom edge of the block-container upwards, making the block-container smaller.
If none of the left, right, top or bottom attributes is specified the block-container will be the same size as the reference area which contains it. This is because the offsets all default to "0pt" so the edges of the block-container are the same as the edges of its containing reference area.
This means a block-container with absolute-position= "absolute" which is placed in a region will by default fill that region.
The height of a block-container can be specified with the height attribute, and the width with the width attribute. Figure 17-3 shows the FO for a block container with height and width of 10cm, and an inner block-container which is offset from the outer one, including a negative offset on the left side. The output from this FO appears in Figure 17-4.
<fo:flow flow-name="body">
<fo:block>
<fo:block-container height="10cm" width="10cm" margin-left="3cm" background-color="#dddddd">
<fo:block>outer block container</fo:block>
<fo:block-container absolute-position="absolute" top="1cm" right="2cm" left="-2cm" bottom="4cm" background-color="#77ccdd">
<fo:block>
inner block-container
</fo:block>
</fo:block-container>
</fo:block-container>
</fo:block>
</fo:flow>