Draw a border around each page on print CSS?

前端 未结 1 1555
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-20 02:39

I need to draw a border around each page when printing. I had originally done this using divs with pagebreak like:

@media print {
.contentContainer {
positio         


        
相关标签:
1条回答
  • 2021-01-20 03:26

    I recommend you to limit the content in a page and then, you can create a simple DIV element with the page-break class.

    <!-- content block -->
    <div class="page-break"></div>
    <!-- content block -->
    

    The CSS:

        @media print{
        .page-break { 
            height:2px; 
            border-top:1px solid #999; 
            margin-bottom:13px;
            page-break-after: always;  
        }
    }
    

    Also, you can insert a page break before each h1 element or after a section:

     h1 {page-break-before: always;}
     section {page-break-after: always; border-bottom:1px solid #999;}
    

    I hope this will help you!

    0 讨论(0)
提交回复
热议问题