我使用window.print()来打印页面,但是我得到了包含页面标题、文件路径、页码和日期的页眉和页脚。如何移除它们?
我也试过打印样式表。
#header, #nav, .noprint
{
display: none;
}请帮帮忙。谢谢。
发布于 2013-03-01 12:55:58
在Chrome中,可以使用以下命令隐藏此自动页眉/页脚
@page { margin: 0; }由于内容将扩展到页面限制,因此页面打印页眉/页脚将不存在。当然,在这种情况下,应该在body元素中设置一些边距/填充,这样内容就不会一直延伸到页面的边缘。由于普通打印机无法进行无页边距打印,而且这可能不是您想要的打印效果,因此您应该使用以下内容:
@media print {
@page { margin: 0; }
body { margin: 1.6cm; }
}正如Martin在评论中指出的那样,如果页面有一个长元素滚动过一页(就像一个大表格),那么页边距就会被忽略,打印出来的版本就会看起来很奇怪。
在这个答案最初出现的时候(2013年5月),它只在Chrome上有效,现在不确定了,再也不需要尝试了。如果你需要支持无法访问的浏览器,你可以动态创建一个PDF并打印(你可以在上面创建一个嵌入JavaScript的自打印PDF ),但这是一个巨大的麻烦。
发布于 2013-06-09 23:26:19
我确信在css文件中添加这段代码会解决这个问题
<style type="text/css" media="print">
@page
{
size: auto; /* auto is the initial value */
margin: 0mm; /* this affects the margin in the printer settings */
}
</style>You may visit this to know more about this
发布于 2016-01-11 21:51:04
CSS标准支持一些高级格式化。CSS中有一个@page指令,它启用了一些仅适用于分页媒体(如纸张)的格式化。参见http://www.w3.org/TR/1998/REC-CSS2-19980512/page.html。
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Print Test</title>
<style type="text/css" media="print">
@page
{
size: auto; /* auto is the current printer page size */
margin: 0mm; /* this affects the margin in the printer settings */
}
body
{
background-color:#FFFFFF;
border: solid 1px black ;
margin: 0px; /* the margin on the content before printing */
}
</style>
</head>
<body>
<div>Top line</div>
<div>Line 2</div>
</body>
</html>
对于firefox,请使用它
在Firefox中,https://bug743252.bugzilla.mozilla.org/attachment.cgi?id=714383 (查看页面来源::tag HTML)。
在您的代码中,用<html moznomarginboxes mozdisallowselectionprint>.替换<html>
https://stackoverflow.com/questions/8228088
复制相似问题