question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use `:host` in selectors to better support web components

See original GitHub issue

Prerequisites

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:open
  • Created a year ago
  • Reactions:8
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
engenbcommented, Jul 8, 2022

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!

<style lang="scss">
@import 'bootstrap';
:root, :host { @extend :root; }
</style>
3reactions
Lausselloiccommented, Jul 7, 2022

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found