/* Sass Variables */ this-slide { $my-color: red; $my-color: yellow; background-color: $my-color; $my-color: green; $my-color: powderBlue; }
/* JS Variables */ let myColor = 'red'; myColor = 'yellow'; thisSlide.style.backgroundColor = myColor; myColor = 'green'; myColor = 'powderBlue';
Imperative languages Follow Steps In Order this-slide { $my-color: red; $my-color: yellow; /* winner! */ background-color: $my-color; $my-color: green; $my-color: powderBlue; }
this-slide { --my-color: red; --my-color: yellow; background-color: var(--my-color); --my-color: green; --my-color: powderBlue; }
Every <button> Needs One Background-Color & One Text Color & One Padding-Left & One Margin-Inline-End & …
on each HTML element For Each Property… Find the relevant/valid declarations Remove duplicate/conflicting properties Fill in any missing properties Resolve any relationships
Need to… Discard Invalid Values this-slide { background-color: red; background-color: yellow; background-color: green; background-color: powderBlue; /* background-color: smashingConf; */ }
Need to… Remove Conflicting Values this-slide { /* background-color: red; */ /* background-color: yellow; */ /* background-color: green; */ background-color: powderBlue; /* background-color: smashingConf; */ }
Need to… Fill in Missing Values this-slide { /* no text `color` was declared, */ /* but we can inherit one! */ }
Finally… Resolve Computed Values this-slide { background-color: rgb(176, 224, 230); /* powderBlue */ color: rgb(0, 0, 0); /* canvasText maybe */ }
Value Resolution Process Filtering Cascading Defaulting (includes inheritance) Resolving (based on type)
this-slide { --my-color: red; --my-color: yellow; background-color: var(--my-color); --my-color: green; --my-color: powderBlue; }
this-slide { /* --my-color: red; */ /* --my-color: yellow; */ background-color: var(--my-color); /* --my-color: green; */ --my-color: powderBlue; }
this-slide { background-color: var(--my-color); --my-color: red; --my-color: yellow; --my-color: green; --my-color: powderBlue; /* winner! */ }
this-slide { background-color: var(--my-color); --my-color: red; --my-color: green; --my-color: powderBlue; --my-color: yellow; /* winner! */ }
A Relevant Declaration… (determined one element at a time) In a stylesheet that applies (see media attr) Not in a false conditional rule (see at-rules) In a selector that matches the HTML Element Is syntactically valid
<integer> / <number> / <dimension> etc… <length> / <angle> / <time> etc… <calc-sum> <color> / <hue> / <alpha-value> <image> / <position> <string> <url> <custom-ident> / <dashed-ident> etc.
You can use it and not use it at the same time, because it works and it doesn’t work at the same time. It’s Quantum CSS! It’s Magic! – Jen Simmons, Intro to Resilient CSS
this-slide { background-color: var(--my-color); --my-color: powderBlue; --my-color: smashingConf; /* 👀👀👀 */ }
✅ Still Valid Syntax html { --my-property: 3em; color: var(--my-property); } html { --my-property: deepPink; }
Declarations containing The var() function or if() function or any --custom() function Are not evaluated at parse time
✅ Still Valid Syntax body { --my-property: 3em; color: var(--my-property); } @property --my-property { syntax: "<color>"; initial-value: teal; inherits: true; }
this-slide { background: maroon !important; --my-color: deepPink !important; --my-color: powderBlue; background: var(--my-color); }
this-slide { background: maroon !important; --my-color: deepPink !important; /* --my-color: powderBlue; */ /* background: var(--my-color); */ }
Each property has an initial value, defined in the property’s definition table. – Cascade & Inheritance, § 7.1. Initial Values
/* initial values */ display: inline; background: transparent; color: CanvasText; font-style: normal; flex-basis: auto; /* etc. */
body { display: initial; } /* inline */ section { display: initial; } /* inline */ div { display: initial; } /* inline */ span { display: initial; } /* inline */ head { display: initial; } /* inline */ title { display: initial; } /* inline */
html, body, p, div, article, aside, header, hgroup, footer, main, nav, section /* etc */ { display: block; } base, basefont, datalist, head, link, meta, script, style, template, title /* etc */ { display: none; }
Fallbacks… Only When Guaranteed Invalid p { --not-a-color: 3em; color: orange; color: var(--not-a-color, green); }
Typed variables Require an Initial-Value @property --border-size { syntax: "<length>"; initial-value: 1px; inherits: false; }
@property --border-size { syntax: "<length>"; initial-value: 12px; inherits: false; } button { border: var(--border-size, thin) solid; }
Explicit defaulting… “Global Keywords” initial (from spec) inherit (from parent element) unset (inherit or initial) revert (from browser) revert-layer (previous layer)
On each element For Each Property Filtering » 0+ ‘declared’ values Cascading » 0-1 ‘cascaded’ values Defaulting » 1 ‘specified’ value Resolving » 1 ‘computed’ value