代码之家  ›  专栏  ›  技术社区  ›  Dipak

打印时,后面的分页符不分页

  •  0
  • Dipak  · 技术社区  · 6 年前

    实际上,什么情况下需要 page-break-after: always before 作品?我试着为 page-break ,即使它在改变浮动时不起作用, clear:both ,但不起作用。

    这里四 sections 只有一页。现在我想 断页 两段后 print ,但没有中断,仍然全部剩余。虽然 margin-bottom 可以替换,但如果分页符有效

    $(document).on('click','#ptn',function(){
      window.print();
    })
    @media print {
      body *{
        visibility: hidden;
      }
      #pay_btn{
        display: none;
      }
      #printDiv, #printDiv * {
          visibility: visible;
       }
       #printDiv {
          width: 297mm;
          height: 210mm;
          position: absolute;
          left:0;
          bottom:0;
          top:0;
          right:0;
       }
       section:nth-child(even) {
        page-break-after: always;
        background:black;
      }
    }
    #printDiv section{
      width:22%;
      margin-right:5px;
      height:70mm;
      float:left;
      border:2px solid red;
      margin-bottom:20px;
    }
    <html>
      <head>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
      </head>
      <body>
      <div class='col100 txtright'><button id='ptn'>Print</button></div>
      <div id='printDiv'>
        <section></section>
        <section></section>
        <section></section>
        <section></section>
       </div>
      </body>
    </html>
    1 回复  |  直到 6 年前
        1
  •  0
  •   anvk    6 年前

    这就是我今天在制作中用到的:

    在我的小档案里

    @media print {
      .page-break {
        display: block;
        page-break-before: always;
      }
    
      .no-print {
        display: none;
      }
    }
    

    然后我的代码里有那些div <div class="page-break"></div>

    它们是我的分页符。打印时,此分页符后面的所有HTML都将位于另一页上