javascript - 在打印 div 内容时,它占用空间和空白页
问题描述
我想在按钮和属性上打印<div>
具有id
使用功能的特定内容。onclick()
window.print()
为此,我写了一些@media print
CSS。
它打印<div>
内容,但需要很多间距,导致空白页。这是我的代码:
@media print {
body * {
visibility: hidden;
}
#printpage,
#printpage * {
visibility: visible;
}
#printpage {
overflow: visible;
position: absolute !important;
left: 0;
top: 0;
}
}
<button type="submit" class="btn btn-primary" onclick="window.print();">Print</button>
<div id="printpage"></div>
解决方案
如何设置具有固定位置的打印页的高度和宽度
@media print {
body{ margin: 0; padding: 0 }
#printpage {
min-height: 100vh; margin: 0; width: 100%; position: fixed; top: 0; left: 0
}
}
推荐阅读
- python - Python Behave 在 except 上引发测试失败
- javascript - 预加载 Google 字体和 CLS
- java - 何时使用 deflate() 的 deflateroutputstream?
- c# - 修改存储在 AsyncLocal 中的对象
- javascript - 如何保存在同一画布上绘制的多个基本形状,并像在油漆中一样预览?
- winapi - CryptVerifyMessageSignature 返回带有附加标头的原始消息,为什么?
- c++ - 在 C++ 中我得到错误:不能将 'bool' 转换为 'bool*' 作为回报
- omegaconf - 从命令行扩展 omegaconf 中的列表
- java - 改造 Gson 反序列化。每个响应都需要它吗?
- wavesplatform - Waves 目前使用 3M 或 3N 作为生成钱包地址的前缀,是否可以将其更改为 AH 而不是 3?