Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set margin-left without it being inherited by child elements?

Tags:

xsl-fo

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?

like image 856
Arne Evertsson Avatar asked Dec 27 '22 22:12

Arne Evertsson


2 Answers

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.

like image 174
it3xl Avatar answered May 16 '23 05:05

it3xl


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>
like image 28
Arne Evertsson Avatar answered May 16 '23 04:05

Arne Evertsson