4 ms·
Don't forget the gigabytes of code spent trying to work around the cascade and produce some kind of framework for styling "components" that doesn't leak crazy s
by ajross 6y ago
Don't forget the gigabytes of code spent trying to work around the cascade and produce some kind of framework for styling "components" that doesn't leak crazy state from the enclosing context (but does inherit the good stuff). The "cascade" was, for sure, a mistake.
Not being in this world, though, I do wonder why there's been no real attempt to fix this from the ground up? I mean... it wouldn't really be "hard" to come up with an alternative metaphor for styling a tree of DOM fragments that compiled to CSS where needed but could be implemented as a first class technology with a proper specification.
Modern browsers have multiple competing implementations of all sorts of other technologies. Why has no one tried to do a new style language? What should it look like?
- Scarbutt 6y agoThe "cascade" was, for sure, a mistake. FWIW, tailwind solves this problem (in a tedious way).
- azangru 6y ago> The "cascade" was, for sure, a mistake. Aren't global styles only possible because of the cascade and the child elements inheriting from parent elements? Without cascade, wouldn't you have to re-declare your font size and font family, and line-height, etc. on every element of your markup?
- im3w1l 6y ago.big-list > li {font-size: 200%}
- im3w1l 6y agoReplying to myself: What if you want to have a link or a span inside your list though? Wouldn't it look weird if they have different size than the surrounding text?
- strbean 6y agoThe cascade is not inheritance. The cascade is deciding the order to apply rules/stylesheets in, and which rule applies here: html: <div><a>Blah</a></div> css: a { color: red; } div a { color: blue; } Where the font color ends up being blue because `div a` is more specific than `a`.
- fireattack 6y agoI assume this is inheritance then? a { color: red; } div { color: blue; } (Blah will be red now.) (I have little knowledge of CSS.)
- bryanrasmussen 6y agoIn a CSS context inheritance is an element inheriting properties of a parent or ancestor - so div { color: blue; } without any definition for what 'a' element color will be, it ends up having the color blue because it inherits it. this is of course why we have the inherit keyword https://developer.mozilla.org/en-US/docs/Web/CSS/inherit https://developer.mozilla.org/en-US/docs/Web/CSS/inherit so you could do div { color: blue; } a { color: red; } .myspecialdivclass a {color: inherit} where myspecialdivclass has the default color of blue and as a result the a elements in it will inherit the color. all that said, inheritance and the cascade sort of leak into each other since they both affect what properties are set for individual elements. on edit: formatting
- azangru 6y agoShoot! My mental picture of a cascade was completely different from what the author of the thesis referenced above had in mind.
- bryanrasmussen 6y agoI have always rather liked the cascade.
- goto11 6y agoThe cascade is what makes it possible to override parts of a stylesheet. Without this, each stylesheet would have to define all styles for every html element in use. It would be an enormous amount of boilerplate in each and every stylesheet.