In my HTML, I've got:
<link rel="stylesheet" href="css/styles.css">
<script src="js/components/custom.js"></script>
...
<custom></custom>
In custom.js
, say I've defined:
class Custom extends HTMLElement {
connectedCallback() {
const shadow = this.attachShadow({mode: 'open'});
shadow.innerHTML = `
<style>
@import url('/css/styles.css');
</style>
...
`
}
}
customElements.define('custom', Custom)
In styles.css
, when I define styles, they work. But I can't do something like
custom img {
}
to target an img
inside custom
. I have to use wrappers like div.custom-contents
to target elements within.
Is this a known limitation perhaps with @import
s like this, custom elements in general, or am I doing something wrong?
` tag using `p { ... }` in CSS. But can't style `` using `custom-element { ... }` in CSS?
– Antrikshy Jan 24 '22 at 19:42