如何在不包含导航选项卡内容、页脚和头部的情况下打印 HTML/PHP 页面


How to print HTML/PHP page without including the NAVIGATION TAB contents, FOOTER, and head part

如何在不包含导航选项卡内容、页脚和头部的情况下打印 HTML/PHP 页面。我使用的是纯 HTML。由于打印的目的,我没有应用CSS...

我实际上正在使用这些代码:

<body onload='window.print(); window.close();'>

<a href="javascript:window.print()">Print</a>

用于打印...

所以在我的页面中,我有一个链接,上面写着"返回",这是一个链接,在转到此打印页面之前,我必须返回到我所在的页面。当我要打印时,CTRL + P,打印时包含BACK链接。打印时如何隐藏它?

您可以使用打印 CSS css media types

<link rel="stylesheet" href="css/print_style.css" media="print" />

在那

.header,.footer,.navigation
{
    display:none;
}

CSS 打印媒体查询

有专门针对印刷媒体的 CSS 媒体查询。

@media print {
   header, footer, nav, aside {
      display: none;
   }
}

更多信息

<style type="text/css" media="print">
    @page 
    {
        size: auto;   /* auto is the initial value */
        margin: 0mm;  /* this affects the margin in the printer settings */
    }
 .navigation,.footer,.header
        {
          display:none;
        }
</style>