w3c / csswg-drafts

CSS Working Group Editor Drafts
https://drafts.csswg.org/
Other
4.5k stars 665 forks source link

[css-env] env(theme-color) or: Access to Author-Specified Document Metadata #575

Open Crissov opened 8 years ago

Crissov commented 8 years ago

Like local element attributes with attr(), it would sometimes be handy to be able to access document-wide meta data, e.g. with HTML:

<meta name="theme-color" content="#F00B42">
h1 {color: meta("theme-color" color, red;)}
h2 {background: meta("theme-color" color, red;)}
upsuper commented 8 years ago

Why not just use CSS variable?

Crissov commented 8 years ago

Over at the WHATWG issue, the original example was:

:root {--ThemeColor: meta("theme-color" color, "theme_color" color, #3F51B5);/* like attr() */}

That means, meta() would be used with CSS Variables, but could also be used without them.

tabatkins commented 6 years ago

This ends up falling under the env() function now, so I'm retagging this as a suggestion for new env() values.

Crissov commented 4 years ago

While theme-color could be added as a predefined environment variable, this issue is probably rather about CSS access to document-specific metadata, which can be divided into author-specified values (e. g. <title> with a fixed key #3685 and <meta> with possibly custom keys #2627 #2629 in HTML) and automatically derived properties (e. g. file size or date and protocol headers, e. g. HTTP). Some metadata that is available for the whole document may also be available for individual (e. g. title from the closest ancestor title attribute in HTML or description from <desc> child in SVG).