Search code examples
htmlcsslaravellaravel-bladedompdf

Top margin on second page does not work - Laravel DOMPDF


When you try to apply top margin on the second page the header does not behave correctly.

Page 1: enter image description here

Page 2: enter image description here

CSS

body {
    font-family: Arial, Helvetica Neue, Helvetica,sans-serif;
    font-size: 14px;
}

@page {
    margin: 100px 25px;
}

header {
    position: fixed;
    top: -70px;
    left: 0px;
    right: 0px;
    height: 50px;
}

main {
    margin-top: 60px;
}

footer {
    position: fixed;
    bottom: -100px;
    left: -60px;
    right: -60px;
    background-color: #3f8d99;
    height: 60px;
    border-top: 1px solid #333;
    font-size: 12px;
    width: 100%;
    padding-top: 6px;
    padding-left: 60px;
    padding-right: 60px;
    color: white;
}

footer .pagenum:before {
    content: counter(page);
}

footer .pagenum-container {
    margin-top: 16px;
    float: right;
}

I tried to follow some ideas, especially from this Post, but I did not succeed.

Thanks for the help.


Solution

  • I found a solution to my problem. I changed some lines of the CSS file.

    @page {
        margin: 140px 25px 100px 25px;
    }
    
    header {
        position: fixed;
        top: -136px;
        left: -60px;
        right: -60px;
        width: 100%;
    }
    

    And removed main class.

    /*main {
        margin-top: 30px;
    }*/
    

    See the result. Page 2:

    enter image description here