Print styles: How to ensure image doesn't span a page break

前端 未结 1 1843
醉酒成梦
醉酒成梦 2020-12-04 11:57

When writing a print stylesheet, is there a way to ensure that an image is always only on a single page, instead of spanning multiple pages. The images much smaller than the

相关标签:
1条回答
  • 2020-12-04 12:12

    The only means I can think of is to use one (or potentially more) of the following css rules:

    img {
        page-break-before: auto; /* 'always,' 'avoid,' 'left,' 'inherit,' or 'right' */
        page-break-after: auto; /* 'always,' 'avoid,' 'left,' 'inherit,' or 'right' */
        page-break-inside: avoid; /* or 'auto' */
    }
    

    I half-recall that these declarations only apply to block-level elements (so you'd also have to define display: block; on your image, or use some kind of wrapping container and apply the rules to that (whether it's in a paragraph, div, span, list, etc...).

    Some useful discussion here: "What are most usefule media="print" specific, cross-browser compatible CSS properties?"

    References:

    • page-break-after.
    • page-break-before.
    • page-break-inside.
    0 讨论(0)
提交回复
热议问题