-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
[v4] preflight removed margins conflicts with web-component :host styles #15864
Comments
I am migrating my existing v3 project to v4 and facing similar issue. Even explicitly defined margin and padding on elements May be applying custom preflight.css without normalizing padding and margin would work but not sure if there is something else I can do as it seems intensional and might be working for everyone else. |
I am experiencing the same issue mentioned here, but in my case, it’s even more complicated because the reset using * { margin: 0; padding: 0; } is part of a theme imported from another project (a library). Modifying this reset is challenging as it risks breaking multiple projects that rely on this theme. My app is wrapped in my theme :
|
I found a workaround for the issue. Instead of importing Tailwind CSS with the default:
I switched to importing only the specific layers I need, like this:
This approach might not be ideal for every use case, but it avoids some of the conflicts caused by the * reset in preflight while still leveraging Tailwind’s utilities. |
I just replaced its preflight with copy of its preflight without margin and padding applied and it solved padding and margin issue.
With this I have started to discover that everything in the preflight gets priority, for example:
I was not able to apply height on I think somehow utility class are not prioritized against preflight.css which I think should not be the case. |
I manage to fix the issue in my case. Somehow I was messing with the priority with my
|
Even without material web-components or any other third-party library preflight's margin setting seems to break the native dialog modal. |
I would suggest, that you create a new issue for that. Because the title of this issue is focused on web-components 🙂 |
What version of Tailwind CSS are you using?
v4.0.0
What build tool (or framework if it abstracts the build tool) are you using?
@tailwindcss/[email protected], [email protected], @material/[email protected]
What version of Node.js are you using?
v22.9.0
What browser are you using?
Firefox 134.0.2, Chromium 132.0.6834.83
What operating system are you using?
Kubuntu 24.10.
Reproduction URL
https://github.com/nilshelmig/tailwindcss-4-webcomponents-bug
Describe your issue
We use material web-components in our project. While upgrading to tailwindcss-v4 we encountered wrong paddings of buttons and wrong position and size of dialog boxes.
It seems because of preflight setting
padding
andmargin
for every element*
to zero, it overrides the styling rules from:host
of the custom-web-elements.Currently, the only workaround I see is to create a custom preflight, so that setting
padding
andmargin
won't apply to:host
elements, or set thepadding
andmargin
for the custom element with tailwindcss. The later one would mean more control on our side, but we have to reapply every sizing of material web-components 😕With preflight enabled
With preflight disabled
The text was updated successfully, but these errors were encountered: