Use `:host` in selectors to better support web components
See original GitHub issuePrerequisites
- I have searched for duplicate or closed feature requests
- I have read the contributing guidelines
Proposal
update css variable selector from :root
to :root,:host
Motivation and context
I want to use Bootstrap 5.x (currently 5.1.3) with a web component. Unfortunately, all the CSS variables defining color, font, etc are not pulled in because web components do not have a :root
. I believe a web component’s counterpart to :root
is :host
(see mdn, here)
I’ll also point out I’m absolutely stealing this “fix” from font awesome
If I edit the bootstrap CSS by updating :root { ... }
to :root,:host { ... }
this corrects the issue.
Is this something that could be updated with Bootstrap to better support web components? I’d be happy to submit a PR.
Issue Analytics
- State:
- Created a year ago
- Reactions:8
- Comments:5 (3 by maintainers)
Top Results From Across the Web
host - CSS: Cascading Style Sheets - MDN Web Docs
The :host CSS pseudo-class selects the shadow host of the shadow DOM containing the CSS it is used inside — in other words,...
Read more >Learn Host & Other Selectors – Web Components
The "Host & Other Selectors" Lesson is part of the full, Web Components course featured in this preview video. Here's what you'd learn...
Read more >How to select :host with a class in css for web components?
From my reading it seems like it is a pseudo-class and pseudo-classes can appear anywhere in a sequence of simple selectors. Also what...
Read more >Angular :host, :host-context, ::ng-deep - The Complete Guide
Angular CLI CSS Preprocessors support - Sass, Less and Stylus; How can we use Sass to improve our styles; Summary. In order to...
Read more >A Web Components Primer - A Beautiful Site
One of the best (and least understood) features of web components is ... you can target the host element in CSS using the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
for anyone else following along, I’m developing my web components with Vue3 and am able to work around this with the following added to my top-most component. would be great if this wasn’t necessary though!
Here’s a sample of the issue with actual
:root
declaration : https://jsbin.com/zazedehola/5/edit?html,js,output Collapse is not well displayed due to shadow dom We need to embed the css inside the component at time : https://jsbin.com/kunonodiro/1/edit?html,js,output This can be avoid if:host
is used and not only:root