Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow at-page rule to be used like a CSS selector #1486

Open
gavin310 opened this issue Jul 7, 2017 · 3 comments
Open

Allow at-page rule to be used like a CSS selector #1486

gavin310 opened this issue Jul 7, 2017 · 3 comments

Comments

@gavin310
Copy link

gavin310 commented Jul 7, 2017

Has anything been done recently to make it easier to change the look for certain pages? I've seen lots of hackish solutions for doing things like having a different header/footer only on the first page, such as covering the header/footer with a white box on the first page and showing custom elements on top of this white box.

I was thinking, what if @page behaved like a normal CSS selector? For example,

@page :nth-child(1) #header-home {
    display: block;
}
@page :nth-child(1) #header-sub {
    display: none;
}
@page :nth-child(1) #some-design-element {
    display: none;
}
@page :nth-child(n+2) #header-home {
    display: none;
}
@page :nth-child(n+2) #header-sub {
    display: block;
}
@page :nth-child(n+2) #some-design-element {
    display: block;
}

Being able to target certain pages would really help when laying out multi-page PDFs, and since the current page number is already available, as well as selectors such as @page :first, it seems like it would be rather simple to include this functionality.

I'm pretty new to dompdf, so maybe there's already a way to accomplish something like this?

Thanks for the awesome library, it's really made my life easier!

@bsweeney
Copy link
Member

This is something I've considered. It doesn't strictly follow the CSS spec, but it seems like a valuable option to have and I haven't come across a better way to handle this type of styling.

@bsweeney
Copy link
Member

this is related to #498

@bsweeney bsweeney removed the On Deck label May 22, 2023
@bsweeney bsweeney changed the title Different elements for different pages... why not make @page function like a CSS selector? Allow at-page rule to be used like a CSS selector May 22, 2023
@zineanteoh
Copy link

Agree that having :nth-child() selector would make it much more powerful! Current selectors are still a little limiting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants