无法将样式应用于动态创建的节点

时间:2015-09-24 16:42:21

标签: polymer polymer-1.0

我创建了一个自定义元素,我从<content>created获取html我使用Polymer.dom(this.root).appendChild(paperItem)paperItem是通过HTML上的迭代创建的。收到<content>)以将其插入本地DOM。好吧,无论我做什么,我都无法从模板的<paper-item>标记中设置<style>。即使Polymer.updateStyles();也无济于事。我错了什么?

1 个答案:

答案 0 :(得分:1)

Here解释如何将样式应用于分发的孩子

<dom-module id="my-element">
  <template>
    <style>
  :host {
    display: block;
    border: 1px solid red;
  }
  #child-element {
    background: yellow;
  }
  /* styling elements distributed to content (via ::content) requires */
  /* selecting the parent of the <content> element for compatibility with */
  /* shady DOM . This can be :host or a wrapper element. */
  .content-wrapper > ::content .special {
    background: orange;
  }
</style>

<div id="child-element">In local DOM!</div>
<div class="content-wrapper"><content></content></div>

 </template>

  <script>

      Polymer({
          is: 'my-element'
      });

  </script>

</dom-module>

  <my-element>
    <div class="special">Here will have a different css </div>
 </my-element>