Replies: 2 comments 2 replies
-
Started playing with web components a bit myself recently and found myself with similar confusion (and it's likely still there). The
The I believe if you want some sure styles on the "component" you'd be better off styling a child of the web component. You'll have full encapsulation there. I think I'd limit what styles I set via host pretty strictly though. You currently have this:
I think If you definitely want all of them set on Curious to hear what others say, though. |
Beta Was this translation helpful? Give feedback.
-
Just to add a bit more context, I'm writing a component library for user defined interfaces, so the goal is to have a set of web components that don't require any external styling. It's all done through the elements and their attributes. The framework is somewhat inspired by the types in SwiftUI, so there are layout/structural components that help with some styling. Most of the time, the styling is internal and not a problem, but there are some cases where you want to control the border or margins of the host, like with the aforementioned structural components like containers that center content with margins and breakpoints. As much as I hate @crswll Just agree with me on the |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm using Tailwind v4 in a project that also uses some web components. The web components are based on Lit, so use
adoptedStyleSheet
for styling the shadow DOM.Any
:host
rules define anything related to border, margin, padding or box-sizing are overrode by this rule from Tailwind's preflight,Any information I can find says that, :host rules should have higher precedence than the universal selector. If you manually turn off these rules in the web inspector, then the expected :host styles appear.
I have included a repro here,
Run the dev server,
And see what's happening. The element should be centered and have a red border, but the preflight resets override it.
What is happening here? How can we have Tailwind in a project with web components and not have it interfere with :host rules?
Beta Was this translation helpful? Give feedback.
All reactions