polymer的伪元素操作(::语法)

原创
2017/07/02 11:49
阅读数 166

Styling distributed children (::content)

Under shady DOM, the <content> tag doesn't appear in the DOM tree. Styles are rewritten to remove the ::content pseudo-element, and any combinator immediately to the left of ::content.

This implies:

  • You must have a selector to the left of the ::content pseudo-element.

    :host ::content div
    

    Becomes:

    x-foo div
    

    (Where x-foo is the name of the custom element.)

  • To limit styles to elements inside the ::content tag, add a wrapper element around the <content>element. This is especially important when using a child combinator (>) to select top-level children.

    <dom-module id="my-element">
    
      <template>
    
        <style>
          .content-wrapper ::content > .special {
            background: orange;
          }
        </style>
    
        <div class="content-wrapper"><content></content></div>
    
      </template>
    
    </dom-module>
    

    In this case, the rule:

    .content-wrapper ::content > .special
    

    Becomes:

    .content-wrapper > .special
    

Custom properties can't style distributed children. The Polymer custom properties shim doesn't support styling distributed children.

展开阅读全文
加载中

作者的其它热门文章

打赏
0
0 收藏
分享
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部