【问题标题】:Removing table's border inside tfoot and thead移除 tfoot 和线程内的表格边框
【发布时间】:2019-01-07 08:22:47
【问题描述】:

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

我的代码:

@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>

【问题讨论】:

    标签: php html css html-table


    【解决方案1】:

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

    @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>
    

    这对你有用。试试吧。 如果有任何问题,请告诉我。

    【讨论】:

    • 按照建议进行了尝试,但 div 页脚现在不会在每一页上重复。它只显示在第三页的顶部(这是最后一页,表格只显示到第 2 页)
    • 我之前没有注意到。您的 HTML 代码格式错误。你为什么不把
    • 我已经更新了我的答案。使用该 HTML 代码,让我知道您的结果是什么。不看代码很难解决这个问题。
    • 通过删除position: fixed; bottom: 0;,最后一页的页脚被放置在tbody的最后一个元素的正下方。这就是我添加带有页脚 ID 的 div 的原因。使用您的最新代码进行了测试,但在tfootthead 区域上仍然可以看到边框。顺便说一句,我正在使用 Chrome 进行测试。
    • 还是一样,我来宾我需要查看 table_content.php 文件是否是导致问题的原因。因为目前里面有很多嵌套表(文件是别人很久以前创建的,所以我真的不知道格式)
    【解决方案2】:

    我无法真正重现您的结果...您能否发布一些显示问题的生成 html(我的意思是,实际上包含表格数据而不是 -stuff)。

    但是,如果我没听错的话,您会尝试为您正在使用的纸张上已经包含的公司页眉和页脚保留标记空间。在这种情况下,我有一个解决方法给你

    1. 添加白色(意思是:background: white;)以固定位置和更高的 z-index 在包含附加标题数据的 html 页面的顶部和底部添加所需的大小 *

      李>
    2. 在 html 页面内容之前和之后添加具有相对定位和页眉/页脚大小的空白 div,因此整个内容不会“低于”其他页眉/页脚元素(我认为使用填充也应该有效,但在这里没有)

    3. 将 thead 和 tfooter 留空 - 只需调整大小,使其不会“低于”其他页眉/页脚元素

    测试一下。

    *) 注意:显然(至少在 Opera 54.0 上)白色背景颜色永远不会被忽略,但如果您的页眉/页脚在打印时看起来是透明的而不是白色,请寻找“打印背景图像”选项

    【讨论】:

    • 我需要在当前模板中添加页眉和页脚(因此使用了include 'table_content.php';)。所以,我使用theadtfoot 标记来实现这一点,但问题是当数据不适合1 页时。水平边框在tfootthead 区域内可见(该区域我用红色突出显示)。
    • 您有解决此问题的示例代码吗?我的页眉和页脚区域仍然有表格边框。
    • 当然。或者,实际上。您能否发布一个 html sn-p,其中 标签被替换为实际内容?然后我会检查我是否可以让我建议的解决方法起作用
    猜你喜欢
    相关资源
    最近更新 更多
    热门标签