在xslfo region-body中垂直拆分页面并为一个部分设置背景颜色
Splitting page vertically in xslfo region-body and setting background color for one section
我花了很多时间尝试在 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>
基本上我试图将主页分成两个垂直部分,然后根据垂直内容较多的部分的高度,我想为左侧部分分配一个占据该高度的背景色。像这样:
同样,如果左侧部分的内容有更高的高度,我将为左侧部分的垂直高度设置绿色背景。
你可以用 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 的 hack。如果你愿意,你可以这样做:
<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>
我花了很多时间尝试在 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>
基本上我试图将主页分成两个垂直部分,然后根据垂直内容较多的部分的高度,我想为左侧部分分配一个占据该高度的背景色。像这样:
同样,如果左侧部分的内容有更高的高度,我将为左侧部分的垂直高度设置绿色背景。
你可以用 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 的 hack。如果你愿意,你可以这样做:
<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>