在xslfo region-body中垂直拆分页面,并为一个部分设置背景颜色

时间:2018-03-28 14:09:20

标签: xsl-fo

我已经尝试了很多个小时来在xslfo中实现一个非常简单的用例,它与此问题css background color with floating elements中描述的非常相似。下面是我到目前为止尝试过的代码示例。

<fo:page-sequence master-reference="A4">
    <fo:flow flow-name="xsl-region-body">
        <fo:block background-color="yellow">
            <fo:float float="left">
                <fo:block width="30%" background-color="red">Hello there
                </fo:block>
            </fo:float>
            <fo:float float="right">
                <fo:block width="70%" background-color="blue">Lorem Ipsum is
                    simply dummy text of the printing and typesetting industry. Lorem
                    Ipsum has been the industry's standard dummy text ever since the
                    1500s, when an unknown printer took a galley of type and
                    scrambled it to make a type specimen book. It has survived not
                    only five centuries, but also the leap into electronic
                    typesetting, remaining essentially unchanged. It was popularised
                    in the 1960s with the release of Letraset sheets containing Lorem
                    Ipsum passages, and more recently with desktop publishing
                    software like Aldus PageMaker including version
                </fo:block>
            </fo:float>
        </fo:block>
        <fo:block clear="both" />       
    </fo:flow>
</fo:page-sequence>

基本上我试图将主页分成两个垂直部分,然后根据垂直有更多内容的部分的高度,我希望为左部分指定占据此高度的背景颜色。像这样:

enter image description here

同样,如果左侧部分的内容有更高的高度,我将为左侧部分的垂直高度设置绿色背景。

1 个答案:

答案 0 :(得分:1)

您可以使用fo:table

执行此操作
        <fo:table background-color="yellow">
            <fo:table-column column-width="30.0%" />
            <fo:table-column column-width="70.0%" />
            <fo:table-body>
                <fo:table-cell background-color="red">
                    <fo:block>Hello there </fo:block>
                </fo:table-cell>
                <fo:table-cell background-color="blue">
                    <fo:block>Lorem Ipsum is simply dummy text of the printing and
                        typesetting
                        industry. Lorem Ipsum has been the industry's standard
                        dummy text ever
                        since the 1500s, when an unknown printer took a
                        galley of type
                        and
                        scrambled it to make a type specimen book. It
                        has survived not only five
                        centuries, but also the leap into
                        electronic typesetting,
                        remaining
                        essentially unchanged. It was
                        popularised in the 1960s with the release
                        of Letraset sheets
                        containing Lorem Ipsum passages, and more
                        recently
                        with desktop
                        publishing software like Aldus PageMaker including
                        version
                    </fo:block>
                </fo:table-cell>
            </fo:table-body>
        </fo:table>

仅使用花车将文本放在正确的位置并不困难。困难的部分是获得较短文本的背景颜色以覆盖其整个一面。

漂浮,但有些黄色背景:

<fo:block-container background-color="yellow">
    <fo:float float="left">
        <fo:block-container width="30%" background-color="red"><fo:block>Hello there</fo:block>
        </fo:block-container>
    </fo:float>
    <fo:float float="right">
        <fo:block-container width="70%" background-color="blue"><fo:block>Lorem Ipsum is
            simply dummy text of the printing and typesetting industry. Lorem
            Ipsum has been the industry's standard dummy text ever since the
            1500s, when an unknown printer took a galley of type and
            scrambled it to make a type specimen book. It has survived not
            only five centuries, but also the leap into electronic
            typesetting, remaining essentially unchanged. It was popularised
            in the 1960s with the release of Letraset sheets containing Lorem
            Ipsum passages, and more recently with desktop publishing
            software like Aldus PageMaker including version</fo:block>
        </fo:block-container>
    </fo:float>
</fo:block-container>

在较短的文字上使用固定的高度并依赖于overflow="hidden",就像你提到的CSS问题一样,是一个黑客IMO。你可以这样做:

<fo:block-container background-color="yellow" overflow="hidden">
        <fo:block-container width="30%" background-color="red">
            <fo:block>Lorem Ipsum is simply dummy text of the printing and typesetting
                industry. Lorem Ipsum has been the industry's standard dummy text ever
                since the 1500s, when an unknown printer took a galley of type and
                scrambled it to make a type specimen book. It has survived not only five
                centuries, but also the leap into electronic typesetting, remaining
                essentially unchanged. It was popularised in the 1960s with the release
                of Letraset sheets containing Lorem Ipsum passages, and more recently
                with desktop publishing software like Aldus PageMaker including version
            </fo:block>
        </fo:block-container>
        <fo:block-container width="70%" absolute-position="absolute" right="0" background-color="blue" height="300px">
            <fo:block>Hello there </fo:block>
        </fo:block-container>
</fo:block-container>

然而,你可以将两者结合起来得到你想要的东西:

<fo:block-container background-color="yellow" overflow="hidden">
    <fo:float float="left">
        <fo:block-container width="30%">
            <fo:block-container absolute-position="absolute" background-color="red" />
            <fo:block>Hello there</fo:block>
        </fo:block-container>
    </fo:float>
    <fo:float float="right">
        <fo:block-container width="70%">
            <fo:block-container absolute-position="absolute" background-color="blue" />
            <fo:block>Lorem Ipsum is simply dummy text of the printing and typesetting
                industry. Lorem Ipsum has been the industry's standard dummy text ever
                since the 1500s, when an unknown printer took a galley of type and
                scrambled it to make a type specimen book. It has survived not only five
                centuries, but also the leap into electronic typesetting, remaining
                essentially unchanged. It was popularised in the 1960s with the release
                of Letraset sheets containing Lorem Ipsum passages, and more recently
                with desktop publishing software like Aldus PageMaker including
                version</fo:block>
        </fo:block-container>
    </fo:float>
</fo:block-container>