I need to set the margin-left and margin-right of all contents within the page header (xsl-region-before). I've tried to add the attribute to a <fo:block> that in turn holds all the header contents. However the margin gets inherited by child blocks which is not what I want.
Is there a way to set the margin without it being inherited?
It's my pain. Every season when I'll start to work with XSL-FO I'll get this trouble.
The Solution. Now and forever.
1 . if you want margins on a external block (my favorite). (Thanks for Yobert.)
<fo:block-container
margin-left="3pt"
margin-right="3pt"
>
<fo:block-container margin="0">
2 . if you'll set margins on a table (I dislike to do this but I should for my team to remember). (Thanks for David Mangon.)
<fo:table
margin-left="3pt"
margin-right="3pt"
>
<fo:table-body
start-indent="0"
end-indent="0"
>
3 . just for a single concrete cell in a table to override indents (<fo:block-container margin="0">). (Thanks to me.)
<fo:table
margin-left="3pt"
margin-right="3pt"
>
<fo:table-body>
<fo:table-row>
<fo:table-cell>
<fo:block-container margin="0">
... content ...
4 . Also the Negative margins of Arne Evertsson (look his answer).
5 . In some weird cases. If you use a padding, then don't forget to add margin="0"
<fo:block-container padding="0 3pt" margin="0">
<fo:block>
6 . If some troubles then think to use the Rule of thumb - don't use padding on a parent, use margins on a child element. In yours layout mastering.
<!-- Set borders. -->
<fo:block-container xsl:use-attribute-sets="borderDefault">
<!-- It's like a padding on a parent. -->
<fo:table-and-caption margin="2pt">
All this approaches were tested.
I found a workaround: Setting the margin to a negative number in the inner block:
<fo:block margin-left="10mm" margin-right="10mm">
<fo:table>
<fo:table-column column-width="100%" />
<fo:table-body>
<fo:table-row>
<fo:table-cell text-align="left">
<fo:block margin-left="-10mm" margin-right="-10mm">
Some text
</fo:block>
</fo:table-cell>
</fo:table-row>
</fo:table-body>
</fo:table>
</fo:block>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With