CSS page-break-inside / after / before不能正常工作

时间:2019-03-15 14:50:58

标签: css wkhtmltopdf page-break page-break-inside

我正在使用wkhtmltopdf将HTML转换为PDF。我担心的是page-break-* : ignore;指令。我试图防止PDF在标题(包括其他标题)之后立即剪切到新页面,因此标题和内容始终粘在一起。不知何故,它似​​乎真的不起作用!我尝试了许多不同的方法,但是结果始终是相同的,忽略了CSS ... page-break-inside: avoid !important;page-break-after: avoid !important;page-break-before: avoid !important;中的任何一个似乎都可以工作。

修改:

我的代码示例为:

index.html

...

<h2>HEADING</h2>
<div class="toctree-wrapper compound"></div>
<p>content content content content content content content 
content content content content content content content content 
content content content content content content content content 
content content content content content content content content 
content content content content content content content content 
content content content </p>

...

style.css

...

p{
    background: green !important;  /* color to see where it breaks */
    page-break-before: avoid !important;
}

h1, h2, h3, h4, h5, h6{
    background: blue !important;  /* color to see where it breaks */
    page-break-after: avoid !important;
    page-break-inside: avoid !important;
}

.toctree-wrapper.compound{
    background: pink !important;  /* color to see where it breaks */
    page-break-after: avoid !important;
    page-break-inside: avoid !important;
    page-break-before: avoid !important;
}

给出以下结果:

enter image description here

有什么想法吗?谢谢!

0 个答案:

没有答案