::slotted CSS selector for nested children in shadowDOM slot

前端 未结 1 785
刺人心
刺人心 2020-11-27 07:36

The CSS ::slotted selector selects children of the element.

however, when trying to select grandchildren like with ::slo

相关标签:
1条回答
  • 2020-11-27 08:09

    styling ::slotted elements in shadowDOM

    TL;DR

    • slotted content remains in lightDOM, is reflected to a <slot>

    • ::slotted(*) can only target the lightDOM SKIN with simple selectors

    • For an example where an Element wraps its lightDOM contents in an extra shadowDOM layer,
      see: https://jsfiddle.net/CustomElementsExamples/Lhcsd2m5/


    background

    Yes, ::slotted() not styling nested elements is expected behavior.

    The term slotted is counterintuitive,
    it implies element lightDOM is moved to shadowDOM

    slotted lightDOM is NOT moved, it remains.. hidden.. in lightDOM
    the content (IF slotted) is reflected to a <slot></slot>

    Or from Google Developer Documentation

    0 讨论(0)
提交回复
热议问题