Is this how @apply works in tailwind?
I'm not a tailwind person but I recall seeing somewhere that there it has something called
@apply
, which might be something I have been wishing were possible in css for a long time.
Namely, I would like to be able to say:
Another way to think about this is that i would like to be able to put multiple properties in a css variable, but of course that’s not possible.
Does @apply work that way in tailwind?17 Replies
no you use TW classes in it
basically at that point you should just make your own util though its bad ig says the creator... was a "gateway for CSS nerds" and mistake
From their docs
🤢 😅
Whatever you do, don’t use @apply just to make things look “cleaner”. Yes, HTML templates littered with Tailwind classes are kind of ugly. Making changes in a project that has tons of custom CSS is worse. If you start using @apply for everything, you are basically just writing CSS again and throwing away all of the workflow and maintainability advantages Tailwind gives you, for example:https://tailwindcss.com/docs/reusing-styles#extracting-classes-with-apply
Huh ok. I don’t get tailwind at all in any case. (I’m fine with CSS.) But I do like the idea of being able to give names to bundles of properties and then reuse those
You should look into Sass (or less/stylus/etc)
if that is what you are after.
https://www.beyondcss.dev/ (plug for Kevin)
Beyond CSS
Take control of your stylesheets with modern CSS and tools like Sass and PostCSS
huh okay thanks
I wonder if something like that might ever end up in the spec.
I guess this
@mixin
business is similar to what i was thinking aboutYa and
@mixins
are being preposed for CSS. So someday
as well as like better interation/loops.do you know if i could see a proposal for mixins? is it on github somewhere?
https://github.com/w3c/csswg-drafts/issues/9350
I think this is the right one
its Miriam so I assume it is
https://css.oddbird.net/sasslike/mixins-functions/
yea it is and been updated
one important thing about scss (sass but actually has the css syntax) is that ANY css file is valid in sass
and you can organize everything into individual files that are compiled into a single css file
@mixin
also lets you use the @contents
, which lets you do something like:
the @contents
will be replaced with the scss inserted into itWhoa that’s crazy
it is stupidly useful
So
$arg1
would be a variable in .any.cssno, it's an argument passed to the mixin
Hmm
imagine something like this:
I should probably understand this, sorry, but where how does
$name
get its value?it's a parameter
mixins work as functions that generate css