CSS Print, header only on first page width css
Asked Answered
T

3

11

I have a logo inside the Logo tags. For printing style i made a @print media query css. If i print it out the logo will printed on every page - but it should only shown on the first page.

Tried with that:

header { display:none; }
@page:first { 
  header { display:block; } 
}

but so the header will deleted on every pages! Any tipps? Thanks

Thorny answered 8/12, 2016 at 11:59 Comment(4)
@page:first header { display:block; } This is enough to do the magicHekate
Possible duplicate of How to use HTML to print header and footer on every printed page of a document?Lustreware
@SelvamElumalai @ page:first header { display:block; } not working for meConfection
@Imran, can you share you code so can I check the css together?Hekate
C
1

You should delete the code

header { display : none; }

because by setting the display property to none. The element will be hidden, and the page will be displayed as if the element is not there.

Casefy answered 9/11, 2022 at 2:11 Comment(0)
C
0

here my css is

@page {
            size: 22cm 29.7cm;
            margin-left: 0mm;
            margin-right: 0mm;
            @top-center {
                content: element(headerOnly1Page)
            }
            @bottom-center {
                content: element(footerOnly1Page)
            }
        }

        div.footerOnly1Page {
            position: running(footerOnly1Page);
        }

        div.headerOnly1Page {
            position: running(headerOnly1Page);
        }

        @page :left {
            @top-center {
                content: ''
            }
            @bottom-center {
                content: ''
            }
        }
        @page :right {
            @top-center {
                content: ''
            }
            @bottom-center {
                content: ''
            }
        }
        @page :first {
            @top-center {
                content: element(headerOnly1Page)
            }
            @bottom-center {
                content: element(footerOnly1Page)
            }
        }

html is

<div class='headerOnly1Page'>
            my header
        </div>
<div class='footerOnly1Page'>
            my footer
        </div>
<div class='content' style="margin-left: 35px; margin-right: 35px">
    my    body
</div>
Consols answered 7/6, 2023 at 11:42 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Simmons
C
-1

You can provide a condition to CSS telling it to not apply the header on any page except the first.

header { display:block; }
@page :not(:first) {
   header { display:none; }
}

The predicate :not(:first) prevents the header being displayed on subsequent pages.

Colloquium answered 15/10, 2021 at 14:17 Comment(2)
Doesn't work, sadly. I assume it's because you can only set basic css properties with :first: developer.mozilla.org/en-US/docs/Web/CSS/:firstShockey
not working! 2022Weeden

© 2022 - 2024 — McMap. All rights reserved.