假设我有带有影子根的 html 元素。
<my-element> #shadow-root <div class='need-target-this' /> </my-element>
如何将 div 定位到 Shadow root 内?
我尝试过使用
:host(my-element.need-target-this)
但这并没有帮助。我在这里缺少什么?
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
在shadowDOM内使用
标签设置shadowDOM的样式
另请参阅::part:https://developer.mozilla.org/en-US/docs/Web/CSS/::part
另请参阅:: :slotted CSS 选择器,用于 ShadowDOM 插槽中的嵌套子级
万一它会对某人有所帮助:我用
div
包装了我的元素,添加了ref
然后去了const Shadow = ref.current.querySelector('my-element').shadowRoot
const target = Shadow?.querySelector('.need-target-this')
target.style.whatever = '值';