Skip to content

Commit 3f30b96

Browse files
committed
Split CSS override advice into Tailwind and native CSS
1 parent b5be040 commit 3f30b96

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

content/collections/pages/vite-tooling.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,27 @@ If you want to use [Tailwind CSS](https://tailwindcss.com) in your addon's compo
134134
135135
You don't need to `@import "tailwindcss"`, as it'll be imported by Statamic's `tailwind.css` file.
136136
137-
#### Overriding Control Panel CSS
137+
### Overriding Control Panel CSS
138138
139-
We organize our CSS using [cascade layers](https://developer.mozilla.org/en-US/docs/Learn_web_development/Core/Styling_basics/Cascade_layers#issues_cascade_layers_can_solve) to help manage styling priorities and avoid conflicts. Internally, we define layers in this order: `@layer base, addon-theme, addon-utilities, components, utilities, ui, ui-states;`. Any CSS you add to your addon will automatically go into the `addon-utilities` layer.
139+
We organize our CSS using [cascade layers](https://developer.mozilla.org/en-US/docs/Learn_web_development/Core/Styling_basics/Cascade_layers#issues_cascade_layers_can_solve) to help manage styling priorities and avoid conflicts. Internally, we define layers in this order: `@layer base, addon-theme, addon-utilities, components, utilities, ui, ui-states;`.
140+
141+
#### Overriding Control Panel CSS using Tailwind
142+
143+
If you use Tailwind, any CSS you add to your addon will automatically go into the `addon-utilities` layer.
140144
141145
We intentionally place addon layers below Statamic’s core layers. This prevents addon styles from unintentionally overriding Statamic's core styles—for instance, an addon's `bg-something` class won’t interfere with Statamic's `dark:bg-something`, which could otherwise cause visual issues like incorrect background colors.
142146
143147
If you do need to explicitly override Statamic’s styles, you can use the Tailwind `!` prefix (e.g., `!lg:grid-cols-3`) to force your class to take priority, which is `!important` under the hood. However, use this technique sparingly, as it will override Statamic’s intended default styling and could introduce unintended side effects.
144148
149+
#### Overriding Control Panel CSS using plain CSS
150+
151+
If you don't use Tailwind, you should still use the `addon-utilities` layer by default, to avoid conflicts with Statamic's core styles.
152+
153+
If you want to override something specific in the CP CSS and your rule is clashing with a core style, there are a couple of different approaches you can take.
154+
155+
1. You can simply write CSS outside cascade layers, which will have higher specificity than Statamic's styles.
156+
2. You can also use the `!important` flag inside `@layer addon-utilities { ... }` to override Statamic's styles.
157+
145158
### Service Provider
146159
Here's `ServiceProvider.php`, which is the PHP entry point to your addon. You should add a `$vite` property which mirrors the paths in your `vite.config.js` file.
147160

0 commit comments

Comments
 (0)