我想在打印时在bordertfoot区域内删除thead。当表格的行分成新页面时,即使在tfoot以及thead区域内,边框也会继续显示。这是问题的屏幕截图:

 

我的代码:



@media print {
  .report-container {
    page-break-after: always;
  }
  thead.report-header {
    display: table-header-group;
  }
  tfoot.report-footer {
    display: table-footer-group;
    border: none;
  }
  #spacer {
    height: 230px;
  }
  #footer {
    position: fixed;
    bottom: 0;
    border: none;
  }
}

<table class="report-container" width="100%" style="" cellspacing="1" cellpadding="5">
  <thead class="report-header">
    <tr>
      <td width="" align="left">
        <?php if ($so_invoice_report_row['has_header_footer']) { echo html_entity_decode($rowHeaderFooter['header_content']); } else {} ?>
      </td>
    </tr>
  </thead>
  <tfoot class="report-footer">
    <tr>
      <td width="" align="left" id="spacer"></td>
    </tr>
  </tfoot>
  <tbody>
    <tr>
      <td>
        <?php
          //include 'table_content.php';
        ?>
        <table border=1 style="border-collapse: collapse;">
        <?php
        for($i=0; $i<=100;$i++) {
	        echo '<tr><td>';
	        echo "Column " . $i . '</td><td> Column2 ';
	        echo '</td></tr>';
        }
        ?>
        </table>
      </td>
    </tr>
  </tbody>
</table>
<div id="footer">
  <?php if ($so_invoice_report_row['has_header_footer']) { echo html_entity_decode($rowHeaderFooter['footer_content']); } else {} ?>
</div>

最佳答案

如下所示从CSS样式表中的position: fixed; bottom: 0;中删除​​了#footer,并为页脚应用了高度值。

@media print {
  .report-container {
    page-break-after: always;
  }
  thead.report-header {
    display: table-header-group;
    background-color:red;
  }
  tfoot.report-footer {
    display: table-footer-group;
    border: none;
    background-color:green;
  }
  tbody {
    background-color:blue;
  }
  #spacer {
    margin-bottom: 150px;
  }
  #footer {
    border: none;
  }
}




<table class="report-container" width="100%" style="" cellspacing="1" cellpadding="5">
  <thead class="report-header">
    <tr>
      <th width="" align="left">
        <?php if ($so_invoice_report_row['has_header_footer']) { echo html_entity_decode($rowHeaderFooter['header_content']); } else {} ?>
      </th>
    </tr>
  </thead>
  <tfoot class="report-footer" id="spacer">
    <tr>
      <td><?php if ($so_invoice_report_row['has_header_footer']) { echo html_entity_decode($rowHeaderFooter['footer_content']); } else {} ?>
      </td>
    </tr>
  </tfoot>
  <tbody>
    <tr>
      <td><?php
          include 'table_content.php';
        ?>
      </td>
    </tr>
  </tbody>
</table>


这将为您工作。尝试一下。
让我知道是否有任何问题。

10-07 14:35