Custom properties affect how invalid CSS declarations are handled (#tilPost)

I recently read Hybrid positioning with CSS variables and max() by Lea Verou and came across a CSS fact that was complete news to me.

The browser doesn’t know if your property value is valid until the variable is resolved, and by t…


This content originally appeared on Stefan Judis Web Development and was authored by Stefan Judis

I recently read Hybrid positioning with CSS variables and max() by Lea Verou and came across a CSS fact that was complete news to me.

The browser doesn’t know if your property value is valid until the variable is resolved, and by then it has already processed the cascade and has thrown away any potential fallbacks.

She describes that when you're using CSS custom properties and the variables turn out to be invalid, fallback mechanisms are no longer possible. You can read more about it in the CSS spec about invalid CSS custom properties.

It includes the following example:

:root { --not-a-color: 20px; }
p { background-color: red; }
p { background-color: var(--not-a-color); }

The above CSS code won't render paragraphs with a red background color. ?

If you want to learn more about it, Jeremy Keith was surprised by an article about this, too, and wrote about it quite nicely.

(which is why I'm not writing about it more detailed)

But... I made a little #devsheet about it. ?


Reply to Stefan


This content originally appeared on Stefan Judis Web Development and was authored by Stefan Judis


Print Share Comment Cite Upload Translate Updates
APA

Stefan Judis | Sciencx (2020-06-28T22:00:00+00:00) Custom properties affect how invalid CSS declarations are handled (#tilPost). Retrieved from https://www.scien.cx/2020/06/28/custom-properties-affect-how-invalid-css-declarations-are-handled-tilpost/

MLA
" » Custom properties affect how invalid CSS declarations are handled (#tilPost)." Stefan Judis | Sciencx - Sunday June 28, 2020, https://www.scien.cx/2020/06/28/custom-properties-affect-how-invalid-css-declarations-are-handled-tilpost/
HARVARD
Stefan Judis | Sciencx Sunday June 28, 2020 » Custom properties affect how invalid CSS declarations are handled (#tilPost)., viewed ,<https://www.scien.cx/2020/06/28/custom-properties-affect-how-invalid-css-declarations-are-handled-tilpost/>
VANCOUVER
Stefan Judis | Sciencx - » Custom properties affect how invalid CSS declarations are handled (#tilPost). [Internet]. [Accessed ]. Available from: https://www.scien.cx/2020/06/28/custom-properties-affect-how-invalid-css-declarations-are-handled-tilpost/
CHICAGO
" » Custom properties affect how invalid CSS declarations are handled (#tilPost)." Stefan Judis | Sciencx - Accessed . https://www.scien.cx/2020/06/28/custom-properties-affect-how-invalid-css-declarations-are-handled-tilpost/
IEEE
" » Custom properties affect how invalid CSS declarations are handled (#tilPost)." Stefan Judis | Sciencx [Online]. Available: https://www.scien.cx/2020/06/28/custom-properties-affect-how-invalid-css-declarations-are-handled-tilpost/. [Accessed: ]
rf:citation
» Custom properties affect how invalid CSS declarations are handled (#tilPost) | Stefan Judis | Sciencx | https://www.scien.cx/2020/06/28/custom-properties-affect-how-invalid-css-declarations-are-handled-tilpost/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.