3 ms·
I've been doing web dev since the 90's and my first reaction to Tailwind was the same. Basically, "are we doing <font> tags again? really?" What the article (a
by thraxil 4y ago
I've been doing web dev since the 90's and my first reaction to Tailwind was the same. Basically, "are we doing <font> tags again? really?"
What the article (and many that are trying to introduce Tailwind) doesn't make clear is that Tailwind is purposely lower level than something like Bootstrap and it really exists to let developers make their own higher level framework.
In particular, the idea is that you use Tailwind's `@apply` to bundle your own components. So you would do:
.card {
@apply md:flex bg-slate-100 rounded-xl p-8 md:p-0 dark:bg-slate-800;
}
.card-img-top {
@apply w-24 h-24 md:w-48 md:h-auto md:rounded-none rounded-full mx-auto;
}
.card-text {
@apply pt-6 md:p-8 text-center md:text-left space-y-4;
}
Then your markup becomes
<figure class="card">
<img class="card-img-top" src="..." ...>
<div class="card-text">
...
You basically can quickly build up your own replacement for Bootstrap out of components that fit well together, handle a lot of the messy implementation/compatibility details for you, and results in a bespoke framework with only exactly what you need and easy to change when you need to.
I think most of the articles and documentation that don't make it clear that Tailwind isn't a direct replacement for Bootstrap, but something that you use to build a better Bootstrap do it a real disservice.
Anyway, I think `@apply` should be one of the first things mentioned when introducing Tailwind. That made it click for me.
I wish it didn't require building/compiling with JS, but I guess we lost that battle way back with SASS/LESS.
- batperson 4y agoWhen it comes up '@apply' I don't really it as an improvement even over vanilla CSS. Seems like tt that point you're basically learning an entirely new syntax just to save time on typing a few characters.
- FireInsight 4y agoJust using @apply isn't really the idea with Tailwind, and iirc one of the devs said they regret it. Tailwind exists in a world with component-based frameworks and advanced editor tooling. Some light repetition is thus toleratred, and it is expected that when more abstraction is needed it can be created using components. Thus you can abstract away non-CSS code too.