You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR adds documentation for the `important` option on the `@import
"tailwindcss";` at-rule.
Remaining questions:
- [ ] Is this the correct spot to document this? (We redirect
`/docs/configuration` to `/docs/theme`, so not 100% sure)
- [ ] Should we document a solution for the `#app` selector strategy
that is mentioned in the v3 docs?
Fixes: #2028
---------
Co-authored-by: Adam Wathan <4323180+adamwathan@users.noreply.github.com>
Copy file name to clipboardExpand all lines: src/docs/styling-with-utility-classes.mdx
+99Lines changed: 99 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -894,3 +894,102 @@ Here's what a `btn-primary` class might look like, using [theme variables](/docs
894
894
</Figure>
895
895
896
896
Again though, for anything that's more complicated than just a single HTML element, we highly recommend using template partials so the styles and structure can be encapsulated in one place.
897
+
898
+
## Managing style conflicts
899
+
900
+
{/* All of the styles in Tailwind have fairly low specificity which can lead to style conflicts */}
901
+
902
+
### Conflicting utility classes
903
+
904
+
When you add two classes that target the same CSS property, the class that appears later in the stylesheet wins. So in this example, the element will receive `display: grid` even though `flex` comes last in the actual `class` attribute:
905
+
906
+
<CodeExampleStack>
907
+
908
+
```html
909
+
<!-- [!code filename:HTML] -->
910
+
<!-- prettier-ignore -->
911
+
<divclass="grid flex">
912
+
<!-- ... -->
913
+
</div>
914
+
```
915
+
916
+
```css
917
+
/* [!code filename: CSS] */
918
+
.flex {
919
+
display: flex;
920
+
}
921
+
.grid {
922
+
display: grid;
923
+
}
924
+
```
925
+
926
+
</CodeExampleStack>
927
+
928
+
In general, you should just never add two conflicting classes to the same element — only ever add the one you actually want to take effect:
Using component-based libraries like React or Vue, this often means exposing specific props for styling customizations instead of letting consumers add extra classes from outside of a component, since those styles will often conflict.
938
+
939
+
### Using the important modifier
940
+
941
+
When you really need to force a specific utility class to take effect and have no other means of managing the specificity, you can add `!` to the end of the class name to make all of the declarations `!important`:
If you're adding Tailwind to a project that has existing complex CSS with high specificity rules, you can use the `important` flag when importing Tailwind to mark _all_ utilities as `!important`:
0 commit comments