浮动保持重叠相邻块

时间:2017-12-15 15:00:13

标签: xsl-fo

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

如何避免我的图标相互重叠?

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

1 个答案:

答案 0 :(得分:2)

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

  1. 放置文本左侧的图标图像。
  2. 避免图标图像和文本的相同序列之间出现图像重叠。
  3. 最好使用更简单的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>
    

    格式化结果:

    Formatting result via AH Formatter