If you toggle display:flex
on a shadow root child it also affects the element outside. (All big browsers behave like this.) Why?
There is a web component with a shadow root:
<web-comp style="display: inline-block;"></web-comp>
Inside the shadow root there is a div with display:flex:
div.style="display:flex; align-items:center; height:50px;"
The complete example:
class demo extends HTMLElement {
connectedCallback() {
const shadow = this.attachShadow({mode: 'open'});
const div = document.createElement('div');
div.innerHTML= "I am in a shadow root!"
div.style="display:flex;align-items:center;height:50px;background:lightblue"
shadow.appendChild(div);
}
}
customElements.define('web-comp', demo);
<h3>flexbox styles do not respect shadow root border</h3>
<web-comp style="display: inline-block;"></web-comp>
And I am not.
<button onclick="document.querySelector('web-comp').shadowRoot.querySelector('div').style.alignItems='baseline'">
Click to change 'align-items' of div in shadow root.
</button>