<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>
<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>
因此,基本思想是有一个 div (不显示任何内容) ,其中包含要打印的项目。现在点击一个按钮不要打印到整个主体,而只是打印特定的 div。使用 window.print ()打印 div (HTML 的一部分)时遇到了很多问题。使用下面的方法,它的工作无缝的边缘,铬和 Mozilla 为我,让我看看它是否也帮助你。