@media print {
body {
visibility: hidden;
}
* {
background: transparent !important;
color: #000 !important;
/* Black prints faster: h5bp.com/s */
box-shadow: none !important;
text-shadow: none !important;
}
thead {
display: table-header-group;
}
tr,
img {
page-break-inside: avoid;
}
img {
max-width: 100% !important;
}
@page {
margin: 0.5cm;
}
p,
h2,
h3 {
orphans: 3;
widows: 3;
}
h2,
h3 {
page-break-after: avoid;
}
//需要指定的打印区域
#section-to-print {
visibility: visible;
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
}
::-webkit-scrollbar {
display: none;
}
.visible-print {
display: block;
width: auto;
height: auto;
overflow: visible;
}
}
<div id="section-to-print"></div>
window.print();
CSS指定打印区域
于 2023-08-08 09:06:09 首次发布