How to load a google font in an encapsulated shadow dom. I am learning web components and couldn't find any way to add a google font URL to the shadow dom. quick help please?
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (4)
Very good question. I never really managed to do it in an encapsulated way. I always ended up adding the link tag in both my component and the client's code (where the component is used). But that totally kills the portability of the component. I'm writing this comment to get a followup on this one.
If you manage to find a way on your own, don't forget to share it with us!
sure. I am reading every single web component article on mdn to find something related to this issue. Currently injecting the link to the client side is the only option I see.
Ex.: Assuming we have in the index.html head a link tag to the google font, eg:
.
In an external index.css file we have declared something like:
:root {
--jos: 'josefin slab';
} .
Then in the web component's style we could do:
:host {
font-family: var(--jos)
}
But I believe you don't want the google font declared in the outside index.html file, so in the WC style we could do something like:
@import url("fonts.googleapis.com/css?family=Jo...);
:host {
font-family: "Josefin Slab";
}
That would work.
This isn't working for me, I can only get the font to load if I put the font
<link>
in the html<head>