News for hackers. Stuff that matters.
Re:Play with TailwindCSS in the Browser by onion2k on Friday June 10, 2022 @08:32AM (#31693143)
It’s like you have to learn every raw CSS selector, and then also learned how it’s represented in Tailwind, and then scatter that all over your markup.

That's exactly what it is.

But... you have to do that regardless of what you use for CSS layout. If you're not using Tailwind (or something like it) then you're going to end up creating classes using the raw CSS, and then naming them yourself, and then having to remember what you called them. Hopefully you're good at that and you can remember, else you'll duplicate things. Hopefully your entire team are aligned on the same naming conventions, or your project's styles will be a total mess.

Maybe you'll use styled-components or another CSS-in-JS solution, which helps a bit by making your styles scoped to components so they don't interfere with things outside of where they should, but then you'll have to keep a set of constants to use across all of them anyway, which puts you back at the same problem as plain CSS - you need to remember what's been set, and not duplicate things.

Ultimately, Tailwind is a really well designed abstraction of inline styles that means you don't have to worry about inconsistency and duplication of things any more. It's another thing to learn but because it's so similar to raw CSS it's not actually a lot of effort. It works well.

Re:Play with TailwindCSS in the Browser by the_other on Friday June 10, 2022 @09:22AM (#31693795)
> If you're not using Tailwind (or something like it) then you're going to end up creating classes using the raw CSS, and then naming them yourself, and then having to remember what you called them.

This is true. But if we better taught the cascade and promoted the idea of global styles rather than pretending it's a problem then more people would be better at this and the problems would gently recede.

We (the high-end front-end dev community) have fallen into the habit of using class names where we really wanted IDs and using components when we really wanted global styles. I feel we have been pushed in this direction by developers who didn't understand the technology properly. The Tailwind author clearly understands it, so I'm not targeting them... but they are supporting the people who don't see why the cascade is useful.

We have megabytes of code to create the impression of global consistency (components, style libraries, CSS-modules...) shipped to millions of users every hour. Browsers do that for us already. Embrace the simplicity of

button { border: foo; color: bar; } .callout button { color: aux; }

It's so clear, so elegant. The obsession with modularising everything, and then applying a DSL to get between the modules, makes the language's inherent convenience, elegance and clarity so much harder to work with that it boggles my mind.

Re:Play with TailwindCSS in the Browser by 1shooner on Friday June 10, 2022 @10:19AM (#31694581)
> It's so clear, so elegant.

The thesis of Tailwind is that the cascade actually becomes very unclear and inelegant at scale, and I would say the reason it's so popular is that many devs share that experience.

Re:Play with TailwindCSS in the Browser by ramesh31 on Friday June 10, 2022 @11:11AM (#31695279)
Cascading is excellent for websites. Terrible for applications. There's no concept of anything even remotely similar in any other UI technology. Native applications have use the "scoped component" paradigm for decades, and the web is finally catching up.
Re:Play with TailwindCSS in the Browser by deergomoo on Friday June 10, 2022 @03:19PM (#31698332)
This is the crux of it really. It makes a whole lot of sense to have cascading styles in documents. I don’t want to have to explicitly set a text colour for each individual paragraph.

But the opposite is largely true for UI elements. For one, I’m probably using some external templating or component framework to repeat them, because they mostly likely have behaviour attached and HTML by itself has no good story for that. For two, I pretty much never want their styling to be modified by the context in which they’re used.

Re:Play with TailwindCSS in the Browser by the_other on Saturday June 11, 2022 @06:31AM (#31703437)
> This is the crux of it really. It makes a whole lot of sense to have cascading styles in documents. I don’t want to have to explicitly set a text colour for each individual paragraph.

But that’s what you’re doing when you use scoped styles, components, Tailwind etc.

Just set it once, on body and forget about it for the lifetime of your app.

> I pretty much never want their styling to be modified by the context in which they’re used.

I guess we have worked on different projects. To me this sounds like the edge case. Most projects I’ve worked on want all the components/widgets/thingies in one consistent style that works together for a cohesive overall experience. For such situations (which to me feel like the majority case) the cascade is the simplest tool.

Re:Play with TailwindCSS in the Browser by 1shooner on Saturday June 11, 2022 @04:13PM (#31707889)
>Most projects I’ve worked on want all the components/widgets/thingies in one consistent style that works together for a cohesive overall experience. For such situations (which to me feel like the majority case) the cascade is the simplest tool.

This is the distinction to me. New methods in composing a page approach this differently: style consistency is maintained through dependencies and a build process rather than relying on context. To understand the styling I'm applying to a given HTML elemnt, I can look to the packages going into the build (just as a I do with other aspects of the code) rather than needing to understand every context my component could possibly be invoked within.

Re:Play with TailwindCSS in the Browser by ryanf on Friday June 10, 2022 @10:28AM (#31694700)
We collectively tried the approach you’re describing, and we stopped doing it because it sucks. It looks nice in simple cases, but the lack of encapsulation or locality makes it impossible to change upstream styles without breaking something somewhere else. Also you have to use horrible BEM-style names to avoid accidental collisions between styles from different parts of your app, which kind of ruins the elegance in itself.
Re:Play with TailwindCSS in the Browser by jsf01 on Friday June 10, 2022 @10:43AM (#31694913)
If your projects are small enough that relying on the cascade is a reliable option, you probably don’t need tailwindcss. If you’re working with 50+ devs on the same code base with many moving parts and shared components, you can’t afford to verify whether the cascade breaks something on every single change. So imo there’s nothing inherently wrong with your post, it’s just that tailwindcss doesn’t really excel until you’re working with a bunch of people authoring css in a shared codebase. (That said, now that I’ve drunk the kool aid I use tailwind or windi css even on my own projects. It’s pretty great once you know it.)
Re:Play with TailwindCSS in the Browser by andiareso on Friday June 10, 2022 @09:42AM (#31694074)
But this isn't much different than:

<Button class=`border text-gray ${override}`/>

<CalloutButton /> extends <Button override="text-blue" />

I'd argue you have less markup to write overall if you are modularizing component logic/styling

Re:Play with TailwindCSS in the Browser by meowtimemania on Friday June 10, 2022 @04:00PM (#31698760)
One gripe I have with tailwind, is overriding styles is difficult. The .text-blue style will only override .text-gray if it is declared later in the css document.

for example if the corresponding css file is this: .text-blue { color: blue; } .text-gray { color: gray; }

Then in your above example, both Button and CalloutButton will have gray text because .test-gray has higher specificity than .text-blue

Re:Play with TailwindCSS in the Browser by xigoi on Saturday June 11, 2022 @05:34AM (#31703171)
The difference is that your website will be much larger and won't work without JavaScript.
Re:Play with TailwindCSS in the Browser by LouisSayers on Friday June 10, 2022 @10:34AM (#31694784)
And what about your :hover, ::before etc, where do you put those? (genuinely curious)
Re:Play with TailwindCSS in the Browser by timdorr on Friday June 10, 2022 @12:05PM (#31696034)
Re:Play with TailwindCSS in the Browser by seek on Friday June 10, 2022 @12:05PM (#31696043)
Re:Play with TailwindCSS in the Browser by azangru on Friday June 10, 2022 @11:55AM (#31695883)
> Hopefully you're good at that and you can remember, else you'll duplicate things. Hopefully your entire team are aligned on the same naming conventions, or your project's styles will be a total mess.

  - CSS classes can be named on a per-component basis, according to one of the well-established naming conventions (BEM, SMACSS, or whatever). This does not require remembering the names of other classes.
  - With the arrival of web components, styles can be scoped within the shadow DOM; and the name collision becomes a non-issue; as well as keeping track of _all_ the CSS that's written in the project. If CSS classes don't leak, you can focus your attention only on a given component and ignore the rest.
  - Instead of CSS-in-JS, one could use CSS modules, which are just regular CSS with a build step. The relevant project-level (site-level, page-level) constants can be defined as CSS constants on the root element.
Re:Play with TailwindCSS in the Browser by holler on Friday June 10, 2022 @07:26PM (#31700466)
my thought exactly, sometimes I wonder when reading about tailwind... naming css classes has been a problem exactly 0 times in recent memory...
Re:Play with TailwindCSS in the Browser by dangerface on Friday June 10, 2022 @11:22AM (#31695432)
It seems like the main advantage of tailwind is that you don't have to learn how CSS cascading and specificity works, which is a fair advantage as most frontend developers I talk to don't even realise that specificity is a thing.

I don't see the advantage over inline style tho. I see abbreviations as a disadvantage as its just as fast to type background as it is bg but background is clearly more intelligible.

How do you deal with side effects for example I think bg-red is the brand red but some one has modified that class so it now has a border. You could prevent this with convention but then you have the same issues as using css with specificity and people not understanding the conventions around it.

I think its easier for every one to just force your frontend developers to just learn CSS and use it.

Re:Play with TailwindCSS in the Browser by tomtheelder on Friday June 10, 2022 @12:08PM (#31696069)
Tailwind is actually a lot like inline styles in certain ways. Whether that's a good thing or not depends on your use case. If you are using a component based framework it ends up, IMO, being way better and less complicated to use the abstraction you already have, your components, as your styling abstraction rather than trying to layer a second abstraction (the cascade approach) on top of it.

The biggest advantage over inline styles is that you are constrained. The idea is that you set up the primitives for your application's styling system: which colors are in use, which font weights, all the way to things like which border radii are valid. Your devs can then only use those.

You are correct that theoretically you can modify them to do anything, but in practice I find that people are extremely unlikely to violate the scheme (in ways like you described, adding a border to bg-red).

As for abbreviations? I think that's probably just eye of the beholder. Since you tend to add a lot of these to your HTML it helps it not get too ridiculously out of hand.

I spent years working with more traditional CSS schemes (including my all time least favorite, BEM), and it was pretty consistently a nightmare within the context of component driven applications. For a while now I've worked with tailwind and it feels like a massive step in the right direction.

I think it's one of those things that really doesn't make sense until you try it and feel the difference for yourself.

Re:Play with TailwindCSS in the Browser by teen on Friday June 10, 2022 @01:19PM (#31696948)
Tailwind has a lot of advantages if you read the documentation rather than conjecture about what you think it might do.
Re:Play with TailwindCSS in the Browser by bavila on Saturday June 11, 2022 @12:06AM (#31701824)
>...which is a fair advantage as most frontend developers I talk to don't even realise that specificity is a thing.

Really? I'm not sure I could take someone seriously if they called themselves a frontend developer and did not understand CSS specificity.

Re:Play with TailwindCSS in the Browser by blain_the_train on Friday June 10, 2022 @10:10AM (#31694475)
> you're going to end up creating classes using the raw CSS

A program can read what looks like inline css and produce class names for youand put those in class files.

When developing your see "height 20px" In your app its compiled to "h-20" with a css file "h-20: height 20"

This is better because you don't have to learn another way to express the same logic.

Re:Play with TailwindCSS in the Browser by pythonaut_16 on Friday June 10, 2022 @10:12AM (#31694500)
So Tailwind with more steps
Re:Play with TailwindCSS in the Browser by xigoi on Saturday June 11, 2022 @05:36AM (#31703187)
Why not use actual inline CSS instead of that?
Re:Play with TailwindCSS in the Browser by calvinmorrison on Friday June 10, 2022 @11:39AM (#31695670)
> That's exactly what it is.

Which is why this is basically reinventing inline styles. With some shorthand.

How did we go from removing <u> and <b> to calling it <div class="bold" an improvement?

Re:Play with TailwindCSS in the Browser by tomtheelder on Friday June 10, 2022 @12:16PM (#31696171)
It's a lot like inline styles. The big advantage is that you create a design language with the helper classes, and then your devs are constrained to use it. No one can add a border radius of 11 if you only have utility classes for 8 and 16, or whatever. Historically you couldn't do that if you were using inline styles.

You could do it with a cascading approach, but if you're building a component based application (this is what Tailwind is really for) then you already have an abstraction for re-usability. Trying to layer another one on top usually results in a really difficult to reason about mess of interlacing components and style classes.

In short it's a way to use an inline-type styling approach, which is suitable for component based apps, without giving up the ability to constrain developers to a limited design language.

There are a TON of other benefits for utility classes over inline, but I think what I described is the biggest one (media queries, pseudo selectors, stylesheet caching for reduced page load, etc.)

> How did we go from removing <u> and <b> to calling it <div class="bold" an improvement?

You can still use <u> and <b> if you want to. Adding a utility bold class also works fine.