How to deal with the issue with WordPress styles and Tailwind's layered styles (weaker)? #16882
-
Hi. I'm working on a new website and use Vite and Tailwindcss v4+, and ACF Blocks. The issue: All WP core, admin or plugins's styles are unlayered, so, they have priority over ANY layered styles. Please, advise how to deal with it.
More details are below: My compiled style file contains layered styles and they can't override any WP/plugins default styles. Frontend:
Backend: Example:
WP common style overrides Tailwindcss classes:
on frontend:
on backend in the block editor (where a block can be rendered too):
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
You could consider unwrapping some of the styles from the -@import "tailwindcss";
+@layer theme, base, components;
+
+@import "tailwindcss/theme.css" layer(theme);
+@import "tailwindcss/preflight.css" layer(base);
+@import "tailwindcss/utilities.css"; And if you still need more specificity (probably for utility classes, you could do something like): @layer theme, base, components;
@import "tailwindcss/theme.css" layer(theme);
@import "tailwindcss/preflight.css" layer(base);
/**
* The `*` will match anything, but the `#a` increases specificity.
* You could replace this for an actual ID selector too, or perhaps
* a class selector would be sufficient.
*/
:is(#a, *) {
@tailwind utilities;
} |
Beta Was this translation helpful? Give feedback.
-
@wongjn Thank you for support. For now it seems the minimal approach with unlayering of utilities works well. I will work with it some time more and if everything is good I will be back here to "Mark as answer". |
Beta Was this translation helpful? Give feedback.
-
So, it seems that it works somehow. Currently my main.css looks like this:
In general the CSS layers are great and they will work well when WP supports them. Until that the layers don't work with WP and you will face with issues all time. WP uses :where() a lot. That and :is() and :has() will help you. Also, in my opinion, I can't say that Taiwind fits with WP with PHP templates (ACF FRO) well. At the same time I can't say that Tailwind does not fit with WP totally. You must take into account that you will face with a lot of different issues due to the "old style" of the PHP approaches of WP. CSS layers are not supported, you need a safelist for some classes, the prettier doesn't work well with PHP templates (but you need it for the class sorting and you will have semi-ugly templates), Vite works in a pretty different way, etc. Of cause all benefits of Tailwind still are present. I'm not say "Don't use Taiwind with WP", just be ready to looking for solutions and deal with work issues. |
Beta Was this translation helpful? Give feedback.
You could consider unwrapping some of the styles from the
@layer
s, like:And if you still need more specificity (probably for utility classes, you could do something like):