在下面的代码中,类.note
是页脚文本,我希望将其打印在除最后一页之外的每一页上。
@media print {
body {
zoom: 85%;
}
p.note {
bottom: -20px;
position: fixed;
margin-top: 10px;
}
}
.page-break {
display: block;
page-break-before: always;
}
<div class="wrappeer">
<p>
<h3>What is Lorem Ipsum?</h3>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing
software like Aldus PageMaker including versions of Lorem Ipsum.
</p>
<div class="page-break"></div>
<p>
<h3>Why do we use it?</h3>
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here,
content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various
versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
</p>
<div class="page-break"></div>
<p>
<h3>Where does it come from?</h3>
Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up
one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum
et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section
1.10.32. The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by
English versions from the 1914 translation by H. Rackham.
</p>
<div class="page-break"></div>
<p>
<h3>Where can I get some?</h3>
There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum,
you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary
of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.
</p>
<p class="note">In the event that you have doubts or irregularities or both, acts of employees and services Please contact the company by dialing <span style="font-size:14px;font-weight: bold;">089 00 89 00</span> or <span style="font-size:14px;font-weight: bold;">08900 89 00.</span></p>
</div>
但是,事实证明,它仅在页面上打印页脚文本。我已经尝试过@page
的CSS3,例如@page:last{}
,@page:last-child{}
和p.note:not(:last){}
来定位最后一页,但是没有帮助。不使用JS,我更喜欢使用任何CSS样式来解决此问题,谢谢。
答案 0 :(得分:1)
阅读文档后,似乎仅使用CSS是不可能的(至2018年底)。似乎@media print无法捕获最后的打印页面。
我会这样解决:
类似的东西:
<script>
var pageBreak = document.getElementsByClassName('page-break');
var note = '<p class="note">In the event that you have doubts or irregularities or both, acts of employees and services Please contact the company by dialing <span style="font-size:14px;font-weight: bold;">089 00 89 00</span> or <span style="font-size:14px;font-weight: bold;">08900 89 00.</span></p>';
for (var i=0; i < pageBreak.length; i++) {
pageBreak[i].insertAdjacentHTML('beforebegin', note);
}
</script>
我想这是唯一应链接以进一步阅读的内容:insertAdjacentHTML
希望它能解决它。
旧的“不工作”建议: 如何用CSS隐藏最后一个.wrapper .note,如:
.wrapper:last-child .note { display:none; }
编辑:
.page-break:last-child + p + .note { display: none}
答案 1 :(得分:0)
希望,您在所有页面中都使用了相同的内容。但是,只需删除一页的页脚文本。因此,我们可以使用常见的javascript代码在特定页面中隐藏该页脚文本。请参见下面的代码,
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript">
var getUrl = window.location.pathname.split('/');
if( getUrl == 'myTest.cfm') {
$(".note").css("display", "none");
}
</script>
首先,我们需要使用JS获取当前文件名。然后,如果条件为true,则检查文件名,页脚文本将被隐藏。
例如,您有3页的意思是,在前两页中将显示页脚文本。但是,我们不需要myTest.cfm(最后一个)页面的页脚文本。因此,使用上面的代码,我们可以隐藏页脚文本。
希望,这会有所帮助。