【问题标题】:Styling descendent element in slotted element在开槽元素中设置后代元素的样式
【发布时间】:2018-01-22 20:09:08
【问题描述】:

是否可以在开槽元素中选择后代元素?

这样的例子:

::slotted(div p) {
        color: blue;
    }

<div><p>test</p><div>

没用

【问题讨论】:

标签: css web-component shadow-dom native-web-component


【解决方案1】:

不可以,您只能选择带有::slotted() 的顶级节点。

::slotted() 中的选择器只能是compound selector,所以div p 是无效的。

根据Hayato Ito

这个限制的原因是为了让选择器样式引擎在性能方面更友好。

请参阅 Shadow Dom v1 演示文稿中的 the styling example

【讨论】:

    猜你喜欢
    • 2019-12-11
    • 2022-07-05
    • 2016-09-28
    • 2023-02-15
    • 1970-01-01
    • 1970-01-01
    • 2021-10-24
    • 2011-02-05
    • 1970-01-01
    相关资源
    最近更新 更多