Let's say you create two custom elements. Each creating a shadow dom. Now you want to select a dom element inside one of these custom elements FROM THE OUTSIDE (I know I could just put my CSS into the custom Elements, but I don't want to do that in this specific case).
In theory this should work without any problem and it works in Firefox and Edge but it doesn't in Chrome (normally it's the other way around). See the following example:
inner-element {
color: blue;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/2.0.2/webcomponents-bundle.js"></script>
<script>
class InnerElement extends HTMLElement {
connectedCallback() {
const shadow = this.attachShadow({
mode: 'open'
});
shadow.innerHTML = "<h1>Inner</h1>";
}
}
window.customElements.define('inner-element', InnerElement);
class OuterElement extends HTMLElement {
connectedCallback() {
const shadow = this.attachShadow({
mode: 'open'
});
shadow.innerHTML = "<h1>Outer</h1><inner-element></inner-element>";
}
}
window.customElements.define('outer-element', OuterElement);
</script>
<outer-element></outer-element>
Does anyone know how my CSS should look like to make it work in all current major browsers?