Kozea / WeasyPrint

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

Add support for the 'vw' and 'vh' css units #1194

Open mousetail opened 4 years ago

mousetail commented 4 years ago

Currently (v51), using vw or vh gives a "invalid value" error. These units would be very useful to style elements relative to the page size. The W3 spec are unclear about the role of vw and vh in paged media, where the CSS units spec refers to the paged media spec which contains no reference to these units. However, I feel like making the units work relative tot the page would be the most useful.

liZe commented 4 years ago

Related to #264.

randomstuff commented 1 week ago

AFAIU, these units are supposed to be relative to page area of the first page.

https://www.w3.org/TR/css-page-3/#page-model

The content area of a page box is called the page area. The content of the document is flowed into one or more page boxes. The page area acts as a container for all the boxes generated by the root element and its descendants that are laid out within a given page box. The edges of the page area on the first page establish the rectangle that is the initial containing block of the document.

https://www.w3.org/TR/css-values-3/#viewport-relative-lengths

vw unit, Equal to 1% of the width of the initial containing block.

vh unit, Equal to 1% of the height of the initial containing block.

liZe commented 1 week ago

AFAIU, these units are supposed to be relative to page area of the first page.

Good to know!

If a size property declaration is qualified by a width, height, device-width, device-height, aspect-ratio, device-aspect-ratio or orientation media query (or other conditional on the size of the paper), then the declaration must be ignored.

So I suspect that vw/vh is ignored in page size.

randomstuff commented 1 week ago

🤔 I have a hard time trying to parse the sentences you quoted :) but I guess are are right.

liZe commented 1 week ago

🤔 I have a hard time trying to parse the sentences you quoted :) but I guess are are right.

Do you mean that CSS is easier to parse than its specification? 😄