Suppose I have a html element with a shadow root.
<my-element> #shadow-root <div class='need-target-this' /> </my-element>
How to position the div inside the Shadow root?
I tried using
:host(my-element.need-target-this)
But that doesn't help. What am I missing here?
Use the
tag within shadowDOM to set the style of shadowDOM
See also::part: https://developer.mozilla.org/en-US/docs/Web/CSS/::part
See also: : :slotted CSS selector for nested children in ShadowDOM slots
In case it helps someone: I wrapped my element with
div
, addedref
and went toconst Shadow = ref.current.querySelector('my-element').shadowRoot
const target = Shadow?.querySelector('.need-target-this')
target.style.whatever = 'value';