HTML Header and footer in all pages while printing html document

后端 未结 4 831
甜味超标
甜味超标 2021-01-18 05:57

I\'ve created a html page with a header,some content and a footer. I tried to get a print of the HTML page, and there was 2 pages. I got the header in first page and the foo

4条回答
  •  不要未来只要你来
    2021-01-18 06:23

    You can target print styles specifically with the "@print" css media style definition. This will allow you to create individual styles strictly for when the document is being printed, and in print preview.

    I would start with this as a solid base.

        @media print {
    
        * {
            color: #000 !important;
            -webkit-text-shadow: none !important;
            text-shadow: none !important;
            font-family: "Times New Roman", Times, serif;
            background: transparent !important;
            -webkit-box-shadow: none !important;
            box-shadow: none !important;
            border: none!important;
            font-weight: normal!Important;
        }
    
        header, nav, footer {
           overflow:visible;
        }
    
        .body {
            width: auto;
            border: 0;
            margin: 0 5%;
            padding: 0;
            float: none !important;
        }
    
    
        a, a:link, a:visited {
    
            &[href]:after {
                content: " (" attr(href) ") ";
                font-size: 90%;
            }
    
            &[href^="javascript:"],
            &[href^="#"] {
                &:after {
                    content: "";
                }
            }
        }
    
        abbr[title]:after {
            content: " (" attr(title) ")";
        }
    
        pre,
        blockquote {
            border: 1px solid #999;
            page-break-inside: avoid;
        }
    
        thead {
            display: table-header-group;
        }
    
        tr,
        img {
            page-break-inside: avoid;
        }
    
        img {
            max-width: 100% !important;
        }
    
        @page {
            margin: 0.5cm;
        }
    
        p,
        h2,
        h3 {
            orphans: 3;
            widows: 3;
        }
    
        h2,
        h3 {
            page-break-after: avoid;
        }
    }
    

提交回复
热议问题