How come xsl-fo padding is being applied to other blocks?

Rick Reumann picture Rick Reumann · Nov 19, 2013 · Viewed 11k times · Source

I'm at a loss trying to understand this. I'm new to using xsl-fo (apache-fop implementation) and I want a block with a border and the content inside padded so it's not bumped up against the border. However when I add the padding, the padding is also applied to the following block?

<fo:page-sequence master-reference="report-page">
<fo:flow flow-name="xsl-region-body">

    <fo:block border="1px solid black" font-size="8pt" margin-bottom="3mm" padding="3mm" >
        <fo:block font-weight="bold">FOO</fo:block>
        <fo:block>ANOTHER BLOCK</fo:block>
    </fo:block>

    <fo:block font-size="8pt">BAR</fo:block>
</fo:flow>

Why does BAR become indented by the amount of padding from the previous block? If I remove the padding on the first block, things line up fine?

Answer

Kevin Brown picture Kevin Brown · Nov 20, 2013

What you should be doing is setting margin to "0mm" and padding to "3mm" on the block if your intention is to have no space outside the border and a 3mm space between the text and the border.

<fo:block border="1px solid black" font-size="8pt" margin="0mm" padding="3mm">
    <fo:block font-weight="bold">FOO</fo:block>
</fo:block>

If the margin-bottom was intended to make space between elements, then you would use space-after or space-before on the following element.