Closed jeanbza closed 8 years ago
What trouble were you running into here? Here is the philosophy on !important in PUI:
The general rule is that modifier classes always have !important and all other classes never have !important.
For example, "bg-neutral-1" sets the background color and nothing else. If you don't want the background color, just don't use the class. It would be really weird if you added a bg-neutral class and your background color didn't change, so we want the !important.
On the other hand "dropdown-toggle" really shouldn't have !important because it incorporates a variety of styles and behaviors, some of which you might not want.
If we have non-modifier classes with !important, we should remove them. Let me know if you run into any.
@charleshansen
In my experience, libraries are imported like this:
<link rel="stylesheet" href="some-library.css">
<link rel="stylesheet" href="some-other-library.css">
<link rel="stylesheet" href="my-library.css">
This is because I fully expect my styles to always take precedence over any other library. Libraries are imported fully-fledged, but my styles start blank slate; so, I should be able to make incremental changes that fit into the existing libraries. In fact, !important
is a tool intended for me to overwrite external library styles! So it's doubly bad that an external library would use this tool; it locks me out of my last-resort method!
On a different note, !important
was an anti-pattern 5-10 years ago when we had to use it to force styles into specific configurations. Today we have many better options, and it continues to be an accepted worse alternative to using specificity to control styles; I've looked through its usage in pivotal-ui and I am (napkin-math level thinking here haha) fairly sure it isn't relied upon - just a nice-to-have. (is that true? i didn't check thoroughly, but it seemed that way)
Lastly, I'll note that other major ui frameworks - such as Google's material ui - don't rely on !important at all.
I believe I agree with everything you stated:
Thanks for the explanation! @charleshansen
https://github.com/pivotal-cf/pivotal-ui/search?utf8=%E2%9C%93&q=%21important