How to make page border in print CSS for every single page

Yasin Yörük picture Yasin Yörük · Jun 23, 2014 · Viewed 16.6k times · Source

I have a long HTML to print. Page is ready for printing but I need to border every single page. I added body { border:2px #666 solid; padding:5px; } in CSS code. HTML view is nice but print view is not. Because border-bottom is not showing first page and border-top is not showing all other pages.

I hope, I can explain what I want. I'm searched and still searching for solution. And I think it's easy trick. But stil not found.

Answer

Mahmoud Moravej picture Mahmoud Moravej · Jun 2, 2018

The best way is putting a fixed div in a page. The important thing is that you should not put any content inside it. It works seamlessly with multi-pages:

<html>
<head>
  <style type="text/css">
    #pageborder {
      position:fixed;
      left: 0;
      right: 0;
      top: 0;
      bottom: 0;
      border: 2px solid black;
    }
  </style>
</head>
<body>
  <div id="pageborder">
  </div>
sdf<br/>
sdf<br/>sdf<br/>sdf<br/>sdf<br/>sdf<br/>sdf<br/>sdf<br/>sdf<br/>sdf<br/>sdf<br/>sdf<br/>
sdf<br/>sdf<br/>sdf<br/>sdf<br/>sdf<br/>sdf<br/>sdf<br/>sdf<br/>sdf<br/>sdf<br/>sdf<br/>sdf<br/>sdf<br/>sdf<br/>sdf<br/>sdf<br/>sdf<br/>sdf<br/>sdf<br/>sdf<br/>sdf<br/>sdf<br/>
111<br/>111<br/>111<br/>111<br/>111<br/>111<br/>111<br/>111<br/>111<br/>111<br/>111<br/>111<br/>111<br/>111<br/>111<br/>111<br/>111<br/>111<br/>111<br/>
111<br/>111<br/>111<br/>111<br/>111<br/>111<br/>111<br/>111<br/>111<br/>111<br/>111<br/>111<br/>111<br/>111<br/>111<br/>111<br/>111<br/>111<br/>111<br/>
222<br/>222<br/>222<br/>222<br/>222<br/>222<br/>222<br/>222<br/>222<br/>222<br/>222<br/>222<br/>222<br/>222<br/>222<br/>222<br/>222<br/>222<br/>222<br/>222<br/>222<br/>222<br/>
</body>
</html>