-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should @apply omit the !important or not #133
Conversation
Hey, this is great :). I think option 2 makes most sense for start and option 3 optionally next (as a separate PR). Similarly to you, I dislike the 'magic' from option 1. Cheers man! |
@mkarnicki Option 2 is the "don't do anything" option and the current behavior. In short:
|
There's a separate bug or comment (perhaps even yours) that suggests that @imporant could be applied to selection of utilities, and I guess that would be the way out. Until then, Option 2 makes most sense. I see no sense in applying a utility - which you know is |
@mkarnicki the problem only appears if you extract components out of your current css. Imagine what happens if all your utliities have This would result in .btn-blue { color: blue !important; } which is good. But if you have a base-component and modifiers this can be tricky. Input: .btn { @apply .bg-grey; }
.btn-blue { color: blue; } Output: .btn { color: 333 !important; }
.btn-blue { color: blue; } => fail. Now you have to add !important yourself, or you're forced to use the |
Makes sense. So this would work if your input was either:
or
assuming there's .blue utility (which there is yet none). I think:
After having this conversation I'm even more happy I'm dropping a CSS kit I purchased in favor of Tailwind, because having no |
Only if you don't have to combine tailwind with legacy CSS.
Tailwind-Classes are Utility-Classes, so i added |
I personally like option 1 the best, which is very easy to implement just by making sure our PostCSS plugins run in the right order, and doesn't feel like magic to me if you have the correct mental model that If you have Imagine To me this is the most useful way for this to work. Don't forget, you can also use For example, you can replace this code:
...with this code, and achieve the same result:
So you always have that escape hatch available. I'm going to close this for now as its really part of the discussion around adding |
Update font family documentation
Hey there,
I am a huge fan of
!important
as you already noticed ;-)In #99 there is an ongoing PR to add some !important functionality to tailwind.
I am not sure how to use it in combination with
@apply
.There are 3 Possibilities.
1. remove
!important
of declarations from@apply
Input
Output
The
!important
is removed.I can add it again if I do something like that.
Input
Output
2. keep
!important
of declarations from@apply
Input
Output
I have no possibility to remove the
!important
easily of class.b
3. keep
!important
of declarations from@apply
but allow removingInput
Output
Input
Output
Opinion
In my opinion utilities used in CSS directly should be important.
One should not be able to overwrite it easily (See The Importantce of !important by csswizardry).
When used in objects, the Base-Objects should not be altered but be immutable.
Instead it should be modified through modifiers.
This is The open/closed principle applied to CSS.
(For "modifier" see BEM, this links is just for documentation purpose when somebody less experienced stumbles upon this issue)
If
@apply
copies!important
the modifier cannot be modify the base-element easily.So Option 2 fails here IMO leaving options 1 and 3 there.
Solution 1 has some "magic". I don't like magic.
But I like the solution more that Number 3 because it does not need any extra effort to write the correct CSS.
What do you think?
I added a failing test with my favor expectation.