Web组件:操纵阴影DOM的CSS
我正在使用iframe
标签的Web组件。
例如:
<my-component>
<!-- SHADOW DOM -->
<iframe>
...
</iframe>
</my-component>
现在,当我尝试样式my-component
如下所示时,它似乎不适用。
my-component {
cursor: default;
}
默认行为是光标:指针
,我想摆脱它。 访问Shadow dom,例如吗?
my-component > iframe {
cursor: default;
}
我可以直接通过CSS 不确定是否可能发生这样的事情。
I am using a web component that has an iframe
tag in its root.
For example:
<my-component>
<!-- SHADOW DOM -->
<iframe>
...
</iframe>
</my-component>
Now when I try to style my-component
as below, it does not seem to apply.
my-component {
cursor: default;
}
The default behaviour is cursor: pointer
and I want to get rid of it. Could I access the shadow DOM via css directly, such as follows?:
my-component > iframe {
cursor: default;
}
Even if the cursor: pointer
is in some deep nested HTML element, I could try and find the target this way, but I'm not sure if such a thing is even possible.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要修改嵌套的Web组件,包含组件的作者必须通过
:: part()
来公开这些组件(在此处阅读更多有关它的信息在阴影中的样式 - dom-with-with-css-shadow-parts/#aa-styling-shadow-dom-with-part“ rel =” nofollow noreferrer“> https://css-tricks.com/stylicks.com/styling--在阴影中 - dom-with-with-css-shadow-parts/#aa-styling-shadow-dom-with-with-part )。否则,您必须使用JavaScript来样式的嵌套Web组件。
如果要到达嵌套在另一个Web组件中的Web组件的阴影,则必须使用ShadowRoot进一步挖掘:
To modify nested web components the author of the containing component must expose these, e.g. through
::part()
(read more about it here https://css-tricks.com/styling-in-the-shadow-dom-with-css-shadow-parts/#aa-styling-shadow-dom-with-part).Otherwise, you have to use JavaScript to style nested web components.
If you want to reach the shadowdom of a web component nested inside another web component, you have to dig further using shadowRoot: