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

@page rules applied for setting different styles are not taking effect as intended. #1330

Closed
jiang0112 opened this issue May 13, 2024 · 3 comments

Comments

@jiang0112
Copy link

I want to set a different style for the same element on the first page compared to the other pages, but the following approach doesn't seem to work.

image
bug
code.txt

@MurakamiShinyu
Copy link
Member

That is not possible in the current CSS Paged Media specification. The @page rule cannot contain style rules. See the spec: https://drafts.csswg.org/css-page-3/#at-page-rule

@jiang0112
Copy link
Author

When my content is filled in, the page automatically paginates, but I need the first and second pages to have different styles. How can I achieve this?

@MurakamiShinyu
Copy link
Member

Vivliostyle.js supports the ::nth-fragment() pseudo-element. So you can use it to apply different styles to the first and second pages. For example, you can use the following CSS:

.base-evaluation::nth-fragment(1) {
  color: blue;
  width: 600px;
}

.base-evaluation::nth-fragment(n+2) {
  color: black;
  width: 800px;
}

Test: https://vivliostyle.vercel.app/#src=https://gist.githubusercontent.com/MurakamiShinyu/fb6ae3973843bf6cd3fd5dca5b5dee5c/raw/issue1330-code-fix.html

By the way, I found a typo in your CSS code: text-transform: uppercasse; should be text-transform: uppercase;.
Also, I think <script src="../../../dist/paged.polyfill.js"></script> is unnecessary in the HTML code. Vivliostyle.js tries to handle scripts but it may cause unexpected results.

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

2 participants