我正在 iOS 11 上的 UIWebView 中构建一个 html 网页。我使用UIPrintFormatter
和UIPrintPageRenderer
(生成 PDF)打印该网页。
page-break-inside: avoid;
不尊重标签container-row
,打印时元素仍会在内部破裂。打破似乎并不总是发生,大多数时候它工作正常。container-row
我在几个地方看到了内部中断,但从未在文本中看到。无论是否使用自定义字体,似乎都会发生内部破坏。
我如何构建 div 及其关联的 css 有问题吗?我怎样才能完全防止container-row
破裂?
整页:https ://jsfiddle.net/2fj13tt7
身体:
<body>
<div class="doc">
<div class="container-row">
<div class="date">
<span>1. July 2017</span>
</div>
<div class="container leftSide">
<div class="item">Item C</div>
<p>Test 123</p>
</div>
</div>
<div class="container-row">
<div class="container rightSide">
<div class="item">Item B</div>
<p>Some Text</p>
</div>
</div>
<div class="container-row">
<div class="container rightSide">
<div class="item">Item A</div>
<img class="image" src="http://via.placeholder.com/350x150">
</div>
</div>
<!-- plus 100 more "container-row" -->
</div>
</body>
CSS:
@font-face {
font-family: 'Liberation Sans';
src: url('LiberationSans-Regular.ttf') format("truetype");
}
@font-face {
font-family: 'LiberationSans-Bold';
src: url('LiberationSans-Bold.ttf') format("truetype");
}
@media print {
.container-row {
page-break-inside: avoid;
}
}
body {
font-family: 'Liberation Sans', sans-serif;
background-color: transparent;
margin: 0 !important;
padding: 0 !important;
}
.container-row {
display: block;
float: left;
width: 100%;
font-family: Liberation Sans, sans-serif;
font-size: 10px;
}
.date {
text-align: center;
margin-top: 20px;
margin-bottom: 10px;
}
.date span {
padding: 5px;
border-radius: 7px;
}
.container {
max-width: 75%;
word-wrap: break-word;
margin: 10px 10px 0px 10px;
overflow: hidden;
}
.leftSide {
float: left;
border-top-left-radius: 13px;
border-top-right-radius: 13px;
border-bottom-right-radius: 13px;
}
.rightSide {
float: right;
border-top-left-radius: 13px;
border-top-right-radius: 13px;
border-bottom-left-radius: 13px;
}
.item {
font-family: 'LiberationSans-Bold', sans-serif;
margin: 7px 10px 1px 10px;
}
.container p {
margin-top: 0px;
margin-left: 10px;
margin-bottom: 7px;
margin-right: 10px;
padding: 0px;
}
.image {
width: 100%;
margin: 5px 0px -5px;
}