Last active
August 18, 2026 12:26
-
-
Save spring-raining/b125a6afd6865ae065704004db8465a5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!doctype html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="utf-8" /> | |
| <title>background-position: var() is dropped on @page</title> | |
| <style> | |
| :root { | |
| --size: 100mm 100mm; | |
| --margin: 15mm; | |
| --bg-image: linear-gradient(#0057b8, #0057b8); | |
| --bg-position: 15mm 12.6mm; | |
| --bg-size: 30mm 5mm; | |
| --bg-repeat: no-repeat; | |
| } | |
| @page { | |
| size: var(--size); | |
| margin: var(--margin); | |
| background-image: var(--bg-image); | |
| background-size: var(--bg-size); | |
| background-repeat: var(--bg-repeat); | |
| } | |
| /* page 1: var() → the bar is drawn at 0 0 */ | |
| @page with-var { | |
| background-position: var(--bg-position); | |
| } | |
| /* page 2: literal → the bar is drawn at 15mm 12.6mm as expected */ | |
| @page with-literal { | |
| background-position: 15mm 12.6mm; | |
| } | |
| section { | |
| break-after: page; | |
| font: 10pt/1.4 sans-serif; | |
| } | |
| #var-page { | |
| page: with-var; | |
| } | |
| #literal-page { | |
| page: with-literal; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <section id="var-page"> | |
| Page 1: <code>@page { background-position: var(--bg-position) }</code><br /> | |
| Expected: blue bar at 15mm / 12.6mm from the page corner. Actual: bar at 0 / 0. | |
| </section> | |
| <section id="literal-page"> | |
| Page 2: <code>@page { background-position: 15mm 12.6mm }</code><br /> | |
| Bar at 15mm / 12.6mm (correct). | |
| </section> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment