News for hackers. Stuff that matters.
Re:Tailwind UI by efdee on Wednesday February 26, 2020 @10:14AM (#22423616)
Judging from all the positive comments in this thread, clearly I must be missing something. This looks horrible to me. Instead of meaningful CSS classes you just get a bunch of small classes that do very small things, which you're supposed to combine until it looks like what you want. How is that better than writing your CSS manually?

(Again, I realise the failure is probably on me. But I don't get it.)

Re:Tailwind UI by iudqnolq on Wednesday February 26, 2020 @10:22AM (#22423710)
Their argument is that the idea of separating content from presentation was always a lie, and that your JS, CSS, and HTML code is always intertwined. I've found this to be partly true for web apps.

Tailwind is essentially unusable without a build step. You can configure it to make composite classes for common styles (button, card, etc.), but if you buy into their philosophy you'll probably want a component-based design (web components, React, Vue, etc).

It's better than working with CSS manually because you work at a slightly higher level. If it was transformed into a css-like language I would prefer that. As a non-UI expert, I also enjoy having an enumerable limited set of sane choices for most properties.

Re:Tailwind UI by deltron3030 on Wednesday February 26, 2020 @11:12AM (#22424270)
>if you buy into their philosophy you'll probably want a component-based design (web components, React, Vue, etc).

With tailwindcss or tachyons you get some of the benefits of component frameworks without having to use component frameworks, because you can colocate html & "styles" in regular template based systems and scope sections on a page this way. Great DX if you need to render sections conditionally, e.g. for ab testing.

If you think in sections rather than individual components anyway, which tailwind kind of promotes by design, you don't gain that much with a component framework.

The actual CSS functions like an inverted triangle (see ITCSS) the utility classes access from the html, so you won't have any specificity issues because it's already sorted out by having the CSS in a fixed order.

Another advantage is portability of sections between modern frontend JS frameworks and template based systems, you can just copy and paste things around, which is harder if the information about the styles is separated from the html, and without a fixed inverted triangle like CSS structure.

Re:Tailwind UI by iudqnolq on Wednesday February 26, 2020 @11:16AM (#22424306)
What if you want every link (from the perspective of the user, not based on the tag type) to have the exact same style? How would you do that without some sort of build step with an atomic unit for a link?

Isn't a section just a case of a component?

Re:Tailwind UI by deltron3030 on Wednesday February 26, 2020 @12:06PM (#22424899)
You could define the anchor element in the preflight.css file (normlize.css/reset).

Yeah, a section is a component, but in my book it also involves the visible page background where the element is located (you could override the page background with a section color), like a slice of the page.

Re:Tailwind UI by iudqnolq on Wednesday February 26, 2020 @12:10PM (#22424930)
Fair enough. I'd call that definition a component.
Re:Tailwind UI by patricius on Wednesday February 26, 2020 @10:30AM (#22423816)
I use Tachyons, which is also utility-based (and, afaik, an inspiration to Tailwind). The primary improvement is that the amount of CSS you need to write is reduced by 90 % or more. Okay, but now you have to write and repeat all these CSS class names, so what have you gained? Not having to write CSS is more than enough for me, but another important thing is that you get all the information you need in one place to see how something is rendered. You also get that with inline styles, but they are much more verbose (at least compared to Tachyon's short class names), and there are some things that you cannot do with inline styles, but can do with classes. But you no longer have to go back and forth between the stylesheet and wherever you are performing your DOM-rendering to get an understanding of what's happening.

Tachyons has truly taken a lot of the pain of writing web applications away for me. It looks kind of ugly in the beginning, but I can't imagine going back to writing oodles of CSS again. Haven't used Tailwind though.

Re:Tailwind UI by SPBS on Wednesday February 26, 2020 @11:09AM (#22424231)
I’m using Tachyons over Tailwind because not needing a build step appeals to me. I vastly prefer the smaller footprint of Tachyons, but I do miss Tailwind’s comprehensive color palette sometimes. I could always manually add it in, but for now I’m sticking to Tachyons’s default colors to keep things simple.
Re:Tailwind UI by kristiandupont on Wednesday February 26, 2020 @10:26AM (#22423754)
I had that same initial reaction when I first read about Tailwind.

I am now a convert and although it's hard for me to articulate exactly where the magic lies, these are contributing factors:

- You can do the entire thing in HTML quickly, including media queries and pseudo-classes.

- The predefined sizes and other values are granular enough that you can do just about everything with them, but coarse enough that you often get it right in the first shot. In a sense, it's a little like going from drawing a chart on blank paper to grid paper.

- Tailwind intellisense in VSCode shows you the colors you likely need.

Each of these points are tiny and could easily be achieved in another way, but combined they have increased my personal joy in frontend development quite significantly.

Re:Tailwind UI by aosaigh on Wednesday February 26, 2020 @10:22AM (#22423713)
The same comment is at the top of every post related to Tailwind. Read this section in the docs and try it out before judging:

https://tailwindcss.com/docs/utility-first

The core principle is that you wrap up all UI elements into components. Most frontend and backend/template frameworks allow you to do this. You then verbosely apply the Tailwind classnames to perform styling, staying out of custom .css files all together.

Re:Tailwind UI by saagarjha on Wednesday February 26, 2020 @10:28AM (#22423791)
This just seems like inline CSS with less verbosity. Where’s the semantic meaning?
Re:Tailwind UI by cageface on Wednesday February 26, 2020 @10:53AM (#22424057)
In my experience trying to do semantic CSS just adds a lot of extra cognitive overhead and breaks down in the inevitable requirements churn every project goes through.

I was skeptical of Tailwind too until I actually tried it. It’s one of those things like JSX that defies received wisdom but in real use is very nice.

Re:Tailwind UI by uk_programmer on Wednesday February 26, 2020 @11:11AM (#22424249)
> In my experience trying to do semantic CSS just adds a lot of extra cognitive overhead.

Do people really struggle with this?

    <div class="hero">
        <h1 class="hero-title">Heading</h1>
        <p class="hero-tagline">Tagline</p>
    </div>
It far more straight forward just to call something what it is and you can actually read the CSS afterwards.
Re:Tailwind UI by cageface on Wednesday February 26, 2020 @06:26PM (#22428624)
Sure in a 4 line example it's fine. On a real site with 5 different kinds of hero elements, with some styles in common but a lot of small variations and each with its own responsive behavior it's not so easy anymore. Coming up with good names for things is one of the hardest jobs in programming and this style forces you to name everything.

I've been building sites the way you suggest for 20 years. I also had a negative knee jerk reaction to tailwind. But I had enough of an open mind to try it and now I have no interesting in going back.

Re:Tailwind UI by uk_programmer on Thursday February 27, 2020 @01:01AM (#22430941)
> Coming up with good names for things is one of the hardest jobs in programming and this style forces you to name everything.

People say that. If you build stuff in components like you are supposed to you almost always have a server side component or component logic that you will have to name. So you are going to have to start naming things properly somewhere.

You are simply kicking the can down the road.

> I've been building sites the way you suggest for 20 years. I also had a negative knee jerk reaction to tailwind.

It isn't a negative kneejerk reaction. I've worked with sites where they have done similar things to tailwind and it is a nightmare to understand what is going on with the page.

> But I had enough of an open mind to try it and now I have no interesting in going back.

The markup is almost unreadable, it completely defeats the point of what CSS is supposed to do and it creates considerable mental overhead for someone who isn't familiar with it.

But I suppose I shouldn't really expect anything else from other web developers that over the last 20 odd years somehow manage to not understand the tech they are given.

Re:Tailwind UI by pdr2020 on Thursday February 27, 2020 @04:07AM (#22431789)
That markup is almost unreadable for you.

And despite your crude last jibe at web developers attracted to Tailwind's model, most competent web developers will be able to quite easily pickup this very sane CSS utility framework :)

Re:Tailwind UI by uk_programmer on Thursday February 27, 2020 @04:26AM (#22431871)
>And despite your crude last jibe at web developers attracted to Tailwind's model,

No my jibe was at web developers in general. CSS and HTML are quite simple really. If you actually keep things semantic and build your document properly with appropriate markup ... lo and behold things just work properly.

I can understand the divistush of the past when CSS 1 and 2 were quite limited. However today there is simply no excuse.

> most competent web developers will be able to quite easily pickup this very sane CSS utility framework :)

Sure I can read it. The problem is with things like this is that you are learning how to work with their model that basically doesn't work like CSS is supposed to work.

So you it essentially nullifies your existing skillset and forces you into using their framework. I bothered to actually learn CSS properly and understand the technology and then I have to work with something which basically throws that all out the window and forces me to work how they want me to build stuff. No thanks.

If you think that is a "sane" way of working, I really don't know what to say.

Re:Tailwind UI by cageface on Thursday February 27, 2020 @04:16AM (#22431826)
People say that. If you build stuff in components like you are supposed to you almost always have a server side component or component logic that you will have to name. So you are going to have to start naming things properly somewhere.

Sure, so you can do it once and use functional css to define the styles that go with that component right alongside the markup instead of having to maintain another css class name for that component in a separate file, mostly likely with arbitrary and inconsistent padding and margin and font-size values.

Re:Tailwind UI by uk_programmer on Thursday February 27, 2020 @04:33AM (#22431899)
If you actually think ahead i.e. don't just start coding straight away you can avoid that. All you are doing is making excuses for not doing your job properly.
Re:Tailwind UI by cageface on Thursday February 27, 2020 @04:46AM (#22431966)
You really sound like someone that's never worked on big projects with changing requirements or a big development team.
Re:Tailwind UI by uk_programmer on Thursday February 27, 2020 @05:00AM (#22432009)
Well you would be wrong then.
Re:Tailwind UI by phponpcp on Wednesday February 26, 2020 @11:21AM (#22424372)
This is so much easier to parse too. If you need more rigidity, add BEM on top then you're good to go.
Re:Tailwind UI by cageface on Wednesday February 26, 2020 @06:29PM (#22428650)
It's easier to parse but what does "hero" actually do? You need to go digging around in all your stylesheets to figure it out and in most cases actually load up the page and inspect it. That overhead is gone in a functional approach.
Re:Tailwind UI by uk_programmer on Thursday February 27, 2020 @05:52AM (#22432237)
If you build things as components as you are supposed to (every backend and frontend framework has been geared around since the late 90s) Your CSS styling should correspond directly to your components (whether they are JS or a MVC partial view). So it should be obvious.

> You need to go digging around in all your stylesheets to figure it out and in most cases actually load up the page and inspect it.

When are you changing CSS and not inspecting the page at the same time? You are going to have to check your work. This doesn't happen if you keep things tidy as you go along. Working in a large team and/or scrum is no excuse for checking-in poor code.

Re:Tailwind UI by deltron3030 on Wednesday February 26, 2020 @12:53PM (#22425398)
You could also describe it with a comment <!-- hero -->, and/or deduce the structure from the actual html elment order.
Re:Tailwind UI by uk_programmer on Wednesday February 26, 2020 @01:39PM (#22425837)
You could however the problem is that the comment will invariably will be left after thing have changed and will just cause confusion.

Generally what the code is doing should be fairly obvious and should not need comments. Comments should be reserved where things aren't obvious.

I don't think it is a good idea to create code where it isnt obvious what it does. CSS is relatively simple tbh things really shouldn't be complicated.

Re:Tailwind UI by deltron3030 on Thursday February 27, 2020 @04:55AM (#22431991)
It might not work in very large teams without an agreed on working style, but I don't see how it would be a problem in smaller teams or for individuals agreeing on using comments to their advantage.
Re:Tailwind UI by rjknight on Wednesday February 26, 2020 @10:21AM (#22423691)
There are some nice aspects:

- The classes cover many common use-cases and, in some cases, present a simpler "API" than hand-rolled CSS would

- You can eyeball a HTML fragment and get a good idea of how the pieces fit together, compared to the normal approach of needing to work out what each individual class does, and then how they fit together. It's easy to remember what the Tailwind classes are doing.

- It's dumb, but the ability copy-and-paste entire HTML fragments from one place to another and have the styling "just work" is slightly mind-blowing

- Some CSS attributes work oddly depending on the order in which they are applied, or the order of the composition of classes that both attempt to apply the same attribute, and that problem goes away with Tailwind

There are other advantages, but these were all quite surprising to me, because my expectations of CSS have always been quite low.

Re:Tailwind UI by hackerman555 on Saturday February 29, 2020 @12:28PM (#22451702)
> It's dumb, but the ability copy-and-paste entire HTML fragments from one place to another and have the styling "just work" is slightly mind-blowing

Not really. styled-components makes this simple if you're using react.

Re:Tailwind UI by dceddia on Wednesday February 26, 2020 @11:30AM (#22424455)
If you have a few minutes, check out a screencast or two from their docs [0]. I was very much in agreement that utility-first looked pretty awful until I saw it in practice.

After watching a few of those I started thinking about how much faster it could be to use these utility classes instead of writing it by hand. Everywhere he adds a few quick classes I was thinking "here I'd be going back to the CSS, hunting for that class name, maybe duplicating it to create a unique variation... and it took him 7 seconds with a utility class. Hm."

Haven't gotten to try it on a project yet but it's on my list.

[0] https://tailwindcss.com/screencasts/

Re:Tailwind UI by Tade0 on Wednesday February 26, 2020 @11:39AM (#22424580)
How is that better than writing your CSS manually?

My take is that it's not. It's just a convenient shortcut for those who aren't well versed in CSS.

I see what kind of problem they're trying to solve, but I think it collapses under its own weight the same as complete, closed components do - just later into the project.

Re:Tailwind UI by wastedhours on Wednesday February 26, 2020 @11:09AM (#22424236)
Not sure how it'd be on a proper-production level app, but for side projects, being able to just iterate on a single element is pretty neat.

I don't necessarily want to remember 30 different context-specific class names when adding a new link or button on a simple page if I know a bit of syntax I can get exactly what I want, when I want it.

Again, it's very much a project specific choice, but when you're playing and tweaking and having fun with a design (or simply, iterating on one element multiple times), it's a nice library.

That being said, I can imagine a point where once you're happy with a design, there'd be a push to refactor.

Re:Tailwind UI by yroc92 on Wednesday February 26, 2020 @10:19AM (#22423676)
I’m with you there. It looks nice, but I don’t want to learn all that css.