Hobbes
Hobbes

Reputation: 2115

Float keeps overlapping adjacent block

I've got a block that contains text, with an icon to the left of this text. When the block only contains one line of text, the icon is higher than the text block. If the next text block has the same structure, the icons will overlap each other. I'm trying to avoid that. I tried using clear="both" -but apparently that only applies to the left/right side of the float, not to the top or bottom.

How can I avoid my icons overlapping each other?

<fo:block clear="both" start-indent="0mm" border="1pt solid black">
    <fo:float float="left" clear="both" >
        <fo:block-container position="absolute"  left="5mm" width="10mm" height="12mm" clear="both">
            <fo:block>
                <fo:external-graphic src="Icon.pdf"  width="10mm" height="10mm" content-width="scale-to-fit"/>
            </fo:block>
        </fo:block-container>
    </fo:float>

    <fo:block margin-left="25mm" clear="both">
        <fo:block>
            <xsl:text>text is inserted here</xsl:text>
        </fo:block>
    </fo:block>
</fo:block>
<fo:block clear="both" start-indent="0mm" border="1pt solid black">
    <fo:float float="left" clear="both" >
        <fo:block-container position="absolute"  left="5mm" width="10mm" height="12mm" clear="both">
            <fo:block>
                <fo:external-graphic src="Icon.pdf"  width="10mm" height="10mm" content-width="scale-to-fit"/>
            </fo:block>
        </fo:block-container>
    </fo:float>

    <fo:block margin-left="25mm" clear="both">
        <fo:block>
            <xsl:text>text is inserted here</xsl:text>
        </fo:block>
    </fo:block>
</fo:block>

Upvotes: 1

Views: 1028

Answers (1)

Toshihiko Makita
Toshihiko Makita

Reputation: 1304

If your want to avoid icon image overlap, it is not a good idea to use fo:block-container with @position=”absolute” because it generates area class “xsl:absolute” which does not affect the main text flow thus @clear attribute is not effective. If the requirements are:

  1. To place the icon image left of the text.
  2. Avoid image overlap between same sequence of icon image and text.

It is better to use more simple fo:list-block formatting object and locate icon image to fo:list-item-label and locate text into fo:list-item-body/fo:block. Here is sample implementation based above:

<fo:list-block provisional-distance-between-starts="25mm" provisional-label-separation="1mm">
    <fo:list-item relative-align="before" border="1pt solid black" space-before="1mm">
        <fo:list-item-label end-indent="label-end()">
            <fo:block>
                <fo:external-graphic src="icon.png"  width="10mm" height="10mm" content-width="scale-to-fit"/>
            </fo:block>
        </fo:list-item-label>
        <fo:list-item-body  start-indent="body-start()">
            <fo:block>text is inserted here text is inserted here text is inserted here text is inserted here text is inserted here text is inserted here text is inserted here text is inserted here text is inserted here text is inserted here text is inserted here text is inserted here text is inserted here text is inserted here text is inserted here</fo:block>
        </fo:list-item-body>
    </fo:list-item>
    <fo:list-item relative-align="before" border="1pt solid black" space-before="1mm">
        <fo:list-item-label end-indent="label-end()">
            <fo:block start-indent="0mm">
                <fo:external-graphic src="icon.png"  width="10mm" height="10mm" content-width="scale-to-fit"/>
            </fo:block>
        </fo:list-item-label>
        <fo:list-item-body start-indent="body-start()">
            <fo:block>text is inserted here text is inserted here</fo:block>
        </fo:list-item-body>
    </fo:list-item>
    <fo:list-item relative-align="before" border="1pt solid black" space-before="1mm">
        <fo:list-item-label end-indent="label-end()">
            <fo:block start-indent="0mm">
                <fo:external-graphic src="icon.png"  width="10mm" height="10mm" content-width="scale-to-fit"/>
            </fo:block>
        </fo:list-item-label>
        <fo:list-item-body start-indent="body-start()">
            <fo:block>text is inserted here text is inserted here</fo:block>
        </fo:list-item-body>
    </fo:list-item>
</fo:list-block>

The formatting result:

Formatting result via AH Formatter

Upvotes: 2

Related Questions