News for hackers. Stuff that matters.
Re:TailwindCSS v2.0 by damnencryption on Wednesday November 18, 2020 @02:32PM (#25141303)
You can use postcss and @apply tag to compose single classes that you can use in your html code like .btn-blue

.btn-blue {

@apply py-2 px-5 flex items-center bg-blue-500 text-white rounded

}

So I don't really see that as a problem. You are supposed to refactor your styles later to be more reusable. What tailwind provides is fast iteration and design. I love that.

Re:TailwindCSS v2.0 by bnt on Wednesday November 18, 2020 @02:46PM (#25141512)
The exact problem is the 99% of people who DON’T do this and their markup ends up a Frankenstein’s monstrosity. I don’t know if it’s the new crop of front-end “developers” who don’t know the very basics or just hipsters being hipsters and YOLO all the things. Tailwind (IMHO) promotes bad practices and needs to explicitly state that you SHOULD use @apply or a puppy somewhere will die.
Re:TailwindCSS v2.0 by dawnerd on Wednesday November 18, 2020 @03:02PM (#25141723)
Oooorrrr some of us just don't care what you might think are good practices. I find tossing classes is more maintainable than trying to refactor down.
Re:TailwindCSS v2.0 by rubans on Wednesday November 18, 2020 @03:22PM (#25141946)
I'm a FE dev with 10 years experience.

I've only started using Tailwind specifically in the last year or so, but I've been using functional CSS for about 6 years.

I don't believe using @apply is a maintainable approach. A better approach is to use view templates. In fact Adam Wathan recommends this way too in this video https://youtu.be/J_7_mnFSLDg

Re:TailwindCSS v2.0 by damnencryption on Wednesday November 18, 2020 @02:54PM (#25141621)
I think you can blame compilation time for that. If you only use tailwind utility classes, there is no need for recompilation on every change but with @apply directive and external CSS file, the thing gets compiled every time you make a change.

I wonder if they can bypass compilation in development mode somehow.

Re:TailwindCSS v2.0 by bigbassroller on Wednesday November 18, 2020 @02:51PM (#25141582)
I second this! I have gone full circle myself. From Dreamweaver (have to start somewhere), hand coding, Bootstrap classes and modifying them, then naturally started using utility classes. Finally made the switch to Tailwind (felt like cheating on a lover, because I loved Bootstrap so much). I then went full on utility classes and low and behold, discovered @apply with nested @screen media queries and went right back to writing clean HTML with named CSS classes that use utility classes in a SCSS file. Its so cool to me, I want to tell everyone about it.
Re:TailwindCSS v2.0 by bigbassroller on Wednesday November 18, 2020 @02:54PM (#25141615)
PS: Plus postcss purge. CSS ecosystem is complete!
Re:TailwindCSS v2.0 by irrational on Wednesday November 18, 2020 @02:56PM (#25141652)
> Plus postcss purge

What does this mean?

Re:TailwindCSS v2.0 by theIV on Wednesday November 18, 2020 @03:01PM (#25141721)
I believe they're referring to https://github.com/FullHuman/purgecss.
Re:TailwindCSS v2.0 by __abc on Wednesday November 18, 2020 @03:09PM (#25141793)
Please, tell me more :)
Re:TailwindCSS v2.0 by bigbassroller on Wednesday November 18, 2020 @06:33PM (#25144143)
Here is an example off the top of my head, while on iphone:

.card { @apply flex flex-row shadow rounded-md p-4; @screen md { @apply flex-col p-6; } yada... yada... }

then in tailwind config, point the purge path to your html file(s) to purge.

End result is css file with no more and no less than what you need, and in the web inspector you see clean HTML markup and clean CSS declarations.

edit: typo

Re:TailwindCSS v2.0 by usaphp on Wednesday November 18, 2020 @02:58PM (#25141680)
that's ridiculous, why not just write padding: 2px 5px; display: flex; align-items: center; color: #fff; You are basically just creating a set of attributes that just mimic standard css properties, I find this approach of tailwind absolutely counter productive, and I am surprised that it gets so much popularity.
Re:TailwindCSS v2.0 by adamzapasnik on Wednesday November 18, 2020 @03:04PM (#25141747)
I think there are two reasons:

- you can copy the classes from html directly into @apply (you need to tinker a bit more to get responsive/hover/etc classes to work, though)

- you work with predefined values, so if you switch color in tailwind.config.js, it's gonna get correct value in the @apply class too.

That's the way I see it

Re:TailwindCSS v2.0 by usaphp on Wednesday November 18, 2020 @05:13PM (#25143155)
2. which values are you going to ever change in align-center, display-flex and text-color-white, it's not like you will change the display flex to mean display block or align center to mean align start, it will always be the same. Same with color white and 95% of other classes that tailwind uses.
Re:TailwindCSS v2.0 by IggleSniggle on Wednesday November 18, 2020 @03:18PM (#25141902)
For the second one, couldn’t you get the same effect by just using css variables?
Re:TailwindCSS v2.0 by adamzapasnik on Wednesday November 18, 2020 @03:28PM (#25142037)
Sure you can and you should, right?

But this way you have to write couple of classes more, couple of variables more. And with Tailwind you just define/change value in the config and you have all the classes generated, so the changes are minimal.

Re:TailwindCSS v2.0 by mstipetic on Wednesday November 18, 2020 @03:38PM (#25142142)
I used to think the same way until i tried it, now i'm completely hooked. it actually makes sense not to extract everything in a "class" simply to separate the presentation out, since that class probably isn't reusable.

plus, it's mostly made to be used with vue/react components which should be small standalone units.

I'm personally looking forward to building websites since using tailwind after a long time

Re:TailwindCSS v2.0 by davidwparker on Wednesday November 18, 2020 @03:14PM (#25141842)
Quick FYI, py-2 is REM based, not pixel. So you know your design will fill properly.
Re:TailwindCSS v2.0 by jaredcwhite on Wednesday November 18, 2020 @03:33PM (#25142098)
Everybody makes @apply out to be the eventual solution to HTML soup, and a project I'm on uses it heavily—BUT the problem is you're now completely locked into a single framework. You can't ditch Tailwind and still use @apply bg-blue-500. If you used regular CSS properties, design tokens via CSS variables, etc. it would be completely portable. I've switched entire sites from one CSS framework to another and it's challenging but doable with standard approaches. With Tailwind, good luck with that…
Re:TailwindCSS v2.0 by rvense on Thursday November 19, 2020 @02:46AM (#25147147)
Um. The Tailwind compiler produces a plain CSS stylesheet with all the classes you need and none of the ones you don't. You can just dig that out of your build (or wget it from production) and stick it where you normally stick your styles(..!).
Re:TailwindCSS v2.0 by jaredcwhite on Friday November 20, 2020 @12:47PM (#25162880)
That's a single output file compiled down from multiple source files likely using a preprocessor…lol. That's not a solution!
Re:TailwindCSS v2.0 by sev on Wednesday November 18, 2020 @02:59PM (#25141687)
Didn't the @apply tag get rejected from the spec? https://www.chromestatus.com/feature/5753701012602880
Re:TailwindCSS v2.0 by systemvoltage on Wednesday November 18, 2020 @02:43PM (#25141458)
I could use sass to do the same.
Re:TailwindCSS v2.0 by damnencryption on Wednesday November 18, 2020 @02:48PM (#25141537)
Yes. You can use tailwind with sass as well though it's not recommended.

Think of tailwind as a framework for all your styling needs while sass is more a functional language to generate CSS for you.

Re:TailwindCSS v2.0 by propelol on Wednesday November 18, 2020 @02:49PM (#25141559)
Partially. You'll lose the system Tailwind gives you, which makes it easier to be consistent.
Re:TailwindCSS v2.0 by systemvoltage on Wednesday November 18, 2020 @03:12PM (#25141821)
I handcraft that system myself.

It's like buy Ikea furniture and assembling it vs. having your own woodworking shop to handcraft furniture with precise requirements. These frameworks have made me lazy. I think CSS design is pretty much exactly the same as any craftsmanship job - there is so much pleasure from building it from the ground up. No, I still get the knots in the wood out by using reset.css.

Also, I try to not use class selectors as much as possible. HTML looks sterile and spartan with only a handful of span tags or id tags for very specialized targetted changes.

I can see why people use frameworks - its fast and quick. But you lose personality in the outcome.

Re:TailwindCSS v2.0 by jwr on Wednesday November 18, 2020 @03:07PM (#25141772)
You mean that @apply tag? https://caniuse.com/css-apply-rule

That is supported by 0% of browsers? Or am I missing something?

Re:TailwindCSS v2.0 by Scarbutt on Wednesday November 18, 2020 @03:19PM (#25141905)
you missed reading 'postcss'