html - 打印时div重叠
问题描述
当我打印以下代码时,绿色页脚与黄色容器重叠。当打印时遇到页脚时,我需要黄色中断并转到下一页。
HTML如下
<body>
<div class="container">
This is the container
</div>
<div class="footer">
This is the footer
</div>
</body>
CSS如下
body{
height: 100vh;
margin: 0;
-webkit-print-color-adjust:exact;
}
.container{
background-color:yellow;
width: 100%;
height: 1500px;
}
.footer{
position: fixed;
bottom: 0;
width: 80%;
height: 100px;
background-color: #21f50056
}
解决方案
最终使用 javascript,在添加任何元素之前,我检查了容器的高度。如果高度超过页面高度,则插入分页符。
推荐阅读
- php - JSON解码多级?
- jquery - 如何获取 HTML 文本的值?
- database - Laravel 加载数据库
- python-3.x - 如何修复 *: 'function' 和 'float' 错误的不受支持的操作数类型
- c# - 保存和加载单选按钮的值不起作用c#
- node.js - 如何在跨域环境中从 ajax 调用调用 nodejs API 并通过将数据返回给 Ajax 来获取响应
- c# - 使用 Json.Net 反序列化时支持多种自定义 DateTime 格式
- c - 缓冲 I/O 的基本实现
- java - 如何修复 IntelliJ 2018.1 代码格式
- c# - 试图理解 ConcurrentQueue 的内存消耗