Polymer 为什么我需要在:host之后编写::shadow?

Polymer 为什么我需要在:host之后编写::shadow?,polymer,Polymer,我正在寻找一个解释,说明为什么我需要编写:host::shadow,以便我的继承元素在我的基本元素的shadow树中为元素设置样式 在以下示例代码中,我希望能够为整个元素设置标签样式: <polymer-element name="my-foo"> <template> <style> :host label { color: red; } </style&g

我正在寻找一个解释,说明为什么我需要编写:host::shadow,以便我的继承元素在我的基本元素的shadow树中为元素设置样式

在以下示例代码中,我希望能够为整个元素设置标签样式:

<polymer-element name="my-foo">
  <template>
      <style>
          :host label {
              color: red;
          }
      </style>
  <label>My label: </label>
  </template>
  <script>
     Polymer('my-foo');
  </script>
</polymer-element>

<polymer-element name="my-bar" extends="my-foo">
  <template>
      <style>
          :host label {
              font-weight: bold;
          }
      </style>
      <shadow></shadow>
      <input />
  </template>
  <script>
    Polymer('my-bar');
  </script>
</polymer-element>

<my-bar></my-bar>

:主机标签{
颜色:红色;
}
我的标签:
聚合物(“my-foo”);
:主机标签{
字体大小:粗体;
}
聚合物(“my-bar”);

上面的示例使标签显示为红色,但不是粗体。为了修复它,我需要将继承元素的样式更改为include::shadow

  <style>
      :host::shadow label {
          font-weight: bold;
      }
  </style>

:主机::阴影标签{
字体大小:粗体;
}

我知道在本例中我处理的是两个shadowroot,我猜::shadow是为了确保我们将样式应用于所有shadowroot,但我认为:host就足够了


有人能解释一下吗?

经过进一步的搜索,我找到了下面这篇文章,我认为这篇文章解释了这一点:


据我所知,
插入点将使我们有必要使用另一个shadowDOM树中的::shadow,因为我们实际上正在跨越边界。阴影边界,也就是说,不是元素边界。

希望这篇由Polymer团队撰写的文章能有所帮助:它并不是真的:(在“元素外部”一节中只提到::Shadow“关键字”。但是,在这种情况下,我不是在元素外部。