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

本文介绍了在Shadow DOM中如何正确地为分布的内容应用样式。重点讲解了使用::content伪元素的限制,以及如何通过包裹元素来解决选择器的问题,并提到了自定义属性在分布内容中的局限性。

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.

转载于:https://my.oschina.net/u/2391658/blog/1113941

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值