News for hackers. Stuff that matters.
Re:Why Tailwind CSS Won by yoav on Wednesday August 16, 2023 @08:58AM (#37146367)
Senior Staff grey beard: Counterpoint: The C in CSS stands for Cascading.

So you’re not learning CSS. You’re learning Tailwind specific classnames that expand to non-cascading style rules.

Re:Why Tailwind CSS Won by danielvaughn on Wednesday August 16, 2023 @09:12AM (#37146546)
This is not true. There's no way to create a "non-cascading style rule" unless the style rule already doesn't cascade. You still have to understand the cascade in order to use Tailwind.
Re:Why Tailwind CSS Won by kevlened on Wednesday August 16, 2023 @09:36AM (#37146791)
While it's true that there's no way to create a "non-cascading style rule", Tailwind allows you to mostly ignore the cascade (except for the normalization stylesheet), because everything is effectively an inline style.

That said, ignoring the cascade is a strength, because the first step in the cascade (css selector specificity) is remarkably complex [0], and can be a source of errors.

[0] https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity

Re:Why Tailwind CSS Won by doix on Wednesday August 16, 2023 @09:31AM (#37146762)
> You still have to understand the cascade in order to use Tailwind.

Can you expand? I haven't used Tailwind, but from looking at the docs, it looks like a short-hand syntax for writing inline styles. Not exactly the same since it can take advantage of media queries and other things that you can't do with inline styles, but close enough conceptually.

Where is the cascade with Tailwind? Perhaps I completely misunderstood how it works, but I would say that it feels like it's purposefully trying kill cascading.

Re:Why Tailwind CSS Won by danielvaughn on Wednesday August 16, 2023 @09:48AM (#37146949)
There are two different things people could be referring to when they mention the "cascade".

One is CSS style inheritance. So if I do this:

  <div class="text-blue-500">
    <i>hello</i>
    <b>world</b>
  <div>
The `text-blue-500` style is going to cascade down to the descendent elements. That's just how CSS works and there's no getting around it.

The other usage of the term applies to a style of writing CSS that makes use of this cascade. So something like this:

  .card {
    color: darkgray;
  }

  .card .header {
    font-size: 20px;
  }
I think what people are referring to in this thread is the latter, which is not the cascade, but a particular approach to CSS.
Re:Why Tailwind CSS Won by doix on Wednesday August 16, 2023 @10:07AM (#37147238)
I mean, the top just happens because color has 'inherit' by default. The latter is specificity, and normally what I think of when I hear "cascading". But, it turns out that isn't cascading either [0].

Cascading refers to the order stylesheets have priority when loaded by the browser. Going to have to update my definitions for the future. I always thought cascading referred to how specificity worked.

Edit: no wait, specificity is part of cascading, cascading refers to the entire process of determining which style applies, including specificity. Inheritance on the other hand is not part of cascading. My definitions were right, don't need to relearn anything.

[0] https://developer.mozilla.org/en-US/docs/Web/CSS/Cascade

Re:Why Tailwind CSS Won by gnagatomo on Wednesday August 16, 2023 @10:20AM (#37147440)
>But, it turns out that isn't cascading either

The order in which stylesheets are loaded and it's origin is just part of the cascading algorithm. See the "Cascading order" section https://developer.mozilla.org/en-US/docs/Web/CSS/Cascade#cas...

Re:Why Tailwind CSS Won by danielvaughn on Wednesday August 16, 2023 @10:50AM (#37147968)
In truth everything mentioned above is part of the overall cascade. CSS takes almost everything into account - stylesheet ordering, rule ordering, rule specificity, etc.
Re:Why Tailwind CSS Won by afiori on Wednesday August 16, 2023 @09:21AM (#37146658)
the cascade has as many benefits as it has drawbacks, few people like to juggle specificities.

IMHO the only important application of the cascade is in its original purpose: custom user defined stylesheets (today often via browser extension or adblockers), but you can add proper descriptive attributes to your markup for them.

Re:Why Tailwind CSS Won by weo3dev on Wednesday August 16, 2023 @10:18AM (#37147406)
In today's uses, cascade _with_ custom properties (the vars defined within :root ) are powerful and are what I leverage when providing theme-able ui libraries. Dark mode, light mode, large mode can all be solved using custom properties which to me most exemplify the power of the cascade.
Re:Why Tailwind CSS Won by afiori on Wednesday August 16, 2023 @12:59PM (#37149994)
that is inheritance not the cascade: Inheritance allows for DOM nodes to use properties set on their ancestors, the cascade algorithm is how multiple conflicting rules interact and are overwritten.

https://developer.mozilla.org/en-US/docs/Web/CSS/Cascade

https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_...

Custom properties are by default inherited by all descendant nodes (they also interact with the cascade, but it is less relevant) and this can be used with tailwind in a couple of different ways: https://stackoverflow.com/questions/64872861/how-to-use-css-...

Re:Why Tailwind CSS Won by iambateman on Wednesday August 16, 2023 @09:09AM (#37146499)
Mid level beard: Tailwind makes most sense in an app developed with components.

So the cascade still happens, just in a different way.

Re:Why Tailwind CSS Won by nkohari on Wednesday August 16, 2023 @10:32AM (#37147650)
Styles applied by Tailwind cascade like any other styles.
Re:Why Tailwind CSS Won by blitz_skull on Wednesday August 16, 2023 @03:19PM (#37152222)
You're not the first person to mention that, to which I counter: Cascading is a mistake in today's component-first web. It works at a very small scale, and _sure_ some things should be cascaded—which Tailwind absolutely lets you do. But 80% of your styles are going to end up scoped to their component—so you might as well use a tool that leverages that concept to its fullest extent.

All my "hard opinions" aside, I have anecdote that no amount of facts can change—I build things faster, more maintainably, that look BETTER than anything I did before Tailwind. Until those pillars stop being true—Tailwind will have my heart.