Kozea / WeasyPrint

The awesome document factory
https://weasyprint.org
BSD 3-Clause "New" or "Revised" License
7.04k stars 669 forks source link

Support media queries #494

Open MattSturgeon opened 7 years ago

MattSturgeon commented 7 years ago

I have the following line in a stylesheet:

@media only screen and (min-width: 480px) {  }
@media only screen and (min-width: 768px) {  }
@media print {  }

When I use this with WeasyPrint I get the following warning:

WARNING: Parse error at 1:8, expected a media type, got IDENT, IDENT, IDENT, (
WARNING: Parse error at 2:8, expected a media type, got IDENT, IDENT, IDENT, (

From what I can tell, the only keyword is not being recognised, so perhaps unknown media types produce a parse error instead of a more descriptive warning and only is an unknown media type?

only is intended to filter out older browsers who don't support media queries but do support comma-separated media types.

liZe commented 7 years ago

Media queries are not supported at all for the moment, it's a good feature to have.

doekman commented 6 years ago

Another use-case for media queries (just making my case to prioritize this issue):

With @media (max-height: you can for example select the first page (because the margins are bigger), and display a complex page footer (for example a table) with display:fixed that only shows up on the first page.

liZe commented 6 years ago

My bad, it's not a good first issue at all:

liZe commented 6 years ago

I've pushed a media-queries branch with initial work for supporting media queries.

Next steps:

liZe commented 6 years ago

I can't work anymore on this point for version 43, it's too long. If anyone is interested, I can help.

liZe commented 6 years ago

With @media (max-height: you can for example select the first page (because the margins are bigger), and display a complex page footer (for example a table) with display:fixed that only shows up on the first page.

We could even add a custom -weasy-page-name feature for that, instead of relying on page size :wink:.

liZe commented 5 years ago

We could even add a custom -weasy-page-name feature for that, instead of relying on page size .

And left/right pages, and page numbers, and…