Hacker News new | past | comments | ask | show | jobs | submit login

why not use web components?



I like the template and slots mechanisms described here:

https://developer.mozilla.org/en-US/docs/Web/API/Web_compone...

and I see some CSS pseudo-classes but I don't see anything I can use to suppress the host site's CSS acting on my UI elements -- am I missing something?


Be default css rules cannot affect the internals of web components. They can only read variables.


if you use the shadow dom, your component won't inherit css rules from the parent site.


I second this suggestion. Web components and the shadow DOM provide a fully isolated "namespace" where you can keep CSS from leaking out into other components. You can still include shared CSS in those files so you get the best of both worlds.


... I just found I can do that with HTMX

https://htmx.org/examples/web-components/

thanks!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: