浮动保持重叠相邻块

Float keeps overlapping adjacent block

我有一个包含文本的块,文本左侧有一个图标。当块只包含一行文本时,图标高于文本块。如果下一个文本块具有相同的结构,图标将相互重叠。我正在努力避免这种情况。我尝试使用 clear="both" - 但显然这只适用于浮动的 left/right 侧,不适用于顶部或底部。

如何避免图标相互重叠?

<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>

如果你想避免图标图像重叠,使用带有@position=”absolute”的fo:block容器不是一个好主意,因为它会生成区域class“xsl:absolute”这不会影响主文本流,因此 @clear 属性无效。 如果要求是:

  1. 将图标图像放在文本的左侧。
  2. 避免相同序列的图标图像和文本之间的图像重叠。

最好使用更简单的 fo:list-block 格式化对象并将图标图像定位到 fo:list-item-label 并将文本定位到 fo:list-item-body/fo:block。 这是基于上面的示例实现:

<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>

格式化结果: