나는 당신이 유효한 값이 될 것 같지 않기 때문에, :second
를 사용하여이 작업을 수행 할 수 있다고 생각하지 않습니다 : 여기에 내가 시도 솔루션입니다.
Index of standard pseudo-classes을 참조하십시오.
단지 : first
을 사용하더라도 위의 링크에서 설명한대로 배경 이미지를 적용 할 수 있다고 생각하지 않습니다.
이미 다른 솔루션을 사용해 보았지만 제대로 작동하지 않았으므로 여기에 해결책이 있습니다.
사이트 레이아웃 및 요구 사항에 따라 페이지를 중단하려는 위치를 예측하고 인쇄 할 때 페이지를 완전히 제어 할 수 있도록 자체 컨테이너에 추가 할 수 있습니다. @page
대한 문서에서
window.print();
body{
background-color: black;
margin: 0px;
}
.page-break{
height: 1054px;
width: 100%;
margin: 0px;
position: relative;
}
#first{background-color: green;}
#second{background-color: pink;}
h1{
padding-top: 5px;
text-align: center;
color: white;
margin: 0px; //Add margin 0px for the first div in page-break
}
h2{
text-align: center;
color: lightblue;
}
@page {
margin: 0;
}
@media print {
html, body {
//style body here
}
.page-break{
page-break-before: always;
}
#first{
\t background-color: maroon;
-webkit-print-color-adjust: exact;
}
#second{
\t background-color: gray;
-webkit-print-color-adjust: exact;
}
#third{
//style the third page;
}
}
<div class="page-break" id="first">
<h1>First Page header</h1>
<h2>Some text here </h2>
</div>
<div class="page-break" id="second">
<h1>Second page header</h1>
<h2>Some text here </h2>
</div>
<div class="page-break" id="third">
<h1>Third page header</h1>
<h2>Some text here </h2>
</div>
: 먼저 작동해야합니다. 그렇지 않습니까? –
배경 이미지 나 색상을 인쇄 할 수있는 권한이 거의 없습니다. 프린터의 기본 설정은 "배경 이미지를 인쇄하지 않음"으로 설정됩니다. 그러나 여기에 대체 방법에 대한 위대한 게시물이 있습니다 : http://stackoverflow.com/questions/6670151/how-can-i-force-browsers-to-print-background-images-in-css –
@SergChernata 예 첫 페이지 만이 아니라 모든 페이지에 적용되며 배경은 '@page : first'에 전혀 적용되지 않습니다 –