cssprinting

How can I avoid an extra blank page at the end while printing?


I'm using a CSS property.

If I use page-break-after: always;, it prints an extra blank page before.

If I use page-break-before: always;, it prints an extra blank page after. How can I avoid this?

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<style type="text/css">
.print{
    page-break-after: always;

}
</style>
<script type="text/javascript">
window.print();
</script>
</head>
<body>
<div class="print">fd</div>
<div class="print">fdfd</div>
</body>
</html>

Solution

  • You could maybe add

    .print:last-child {
         page-break-after: auto;
    }
    

    so the last print element will not get the extra page break.

    Do note that the :last-child selector is not supported in Internet Explorer 8, if you're targetting that wretch of a browser.