我想用它只打印
#section-to-print
:
@media print {
body * {
visibility: hidden;
}
#section-to-print, #section-to-print * {
visibility: visible;
}
#section-to-print {
position: absolute;
left: 0;
top: 0;
}
}
如何扩展它以在屏幕上显示时隐藏
#section-to-print
? 换句话说,它只有在打印介质时才可见。
将其设置为visibility:hidden,然后@media print可以覆盖它。
#section-to-print, #section-to-print * {
visibility: hidden;
}
@media print {
body * {
visibility: hidden;
}
#section-to-print, #section-to-print * {
visibility: visible;
}
#section-to-print {
position: absolute;
left: 0;
top: 0;
}
}