本文介绍了谷歌浏览器打印分页符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让谷歌浏览器进行分页.

通过一堆网站告诉我 page-break-after: always; 在 chrome 中是有效的,但即使使用一个非常简单的例子,我似乎也无法让它工作.在 chrome 中打印时有什么方法可以强制分页吗?

解决方案

我已经在包括 Chrome 在内的所有主流浏览器中成功使用了以下方法:

这是一个简化的例子.在实际代码中,每个页面 div 包含更多元素.

I'm trying to get google chrome to do page breaks.

I've been told via a bunch of websites that page-break-after: always; is valid in chrome but I can not seem to get it to work even with a very simple example. is there any way to force a page break when printing in chrome?

解决方案

I've used the following approach successfully in all major browsers including Chrome:

<!DOCTYPE html>

<html>
  <head>
    <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
    <title>Paginated HTML</title>
    <style type="text/css" media="print">
      div.page
      {
        page-break-after: always;
        page-break-inside: avoid;
      }
    </style>
  </head>
  <body>
    <div class="page">
      <h1>This is Page 1</h1>
    </div>
    <div class="page">
      <h1>This is Page 2</h1>
    </div>
    <div class="page">
      <h1>This is Page 3</h1>
    </div>
  </body>
</html>

This is a simplified example. In the real code, each page div contains many more elements.

这篇关于谷歌浏览器打印分页符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 02:09
查看更多