CSS隐藏表格列以供打印

问题描述:

我有表数据,最后一列包含对该数据进行操作的链接.我希望有人打印页面时最后一列不可见.

I have table data and last column contains links for actions on that data. I would like that last column not visible when someone prints the page.

我尝试了以下操作,并且可以在屏幕上使用(看不到最后一列,其余各列均匀分布以填充该空间).

I tried the following and it works on screen (don't see last column, and rest of the columns are evenly spread to fill that space).

@media print {
  table td:last-child {display:none}
}

但是它不适用于打印:我看不到该列,但该列有空白.

But it doesn't work for print: I don't see the column, but there is empty space where it was.

这对我有用:

   @media print {
       table td:last-child {display:none}
       table th:last-child {display:none}
   }