简体   繁体   English

聚合物样式不影响主体元素

[英]Polymer styles not taking affect on host element

I have the following simple Polymer 1.0 custom element: 我有以下简单的Polymer 1.0自定义元素:

<dom-module id="my-custom-element">
    <style>
        :host {
            display: block;
        }
        .grow {
          min-height: 100%;
          height: 100%;
        }
    </style>
    <template>
        <content></content>
    </template>
</dom-module>
<script>
(function() {
  Polymer({
    is: 'my-custom-element',

    properties: {
    },
    ready: function () {

       //this doesn't work
       this.classList.add('grow');

       //this works (if uncommented)
       //this.style.height = '100%';
       //this.style.minHeight= '100%';

    }
  });
})();

I'm trying to add the grow css class to the host. 我正在尝试将grow CSS类添加到主机。 For some reason the styles only take affect if I set them individually as follows: 出于某种原因,这些样式仅在我按如下方式分别设置时才会生效:

 this.style.height = '100%';
 this.style.minHeight= '100%';

It has no affect if instead I assign the class: 相反,如果我分配该类,则没有任何影响:

 this.classList.add('grow');

Why is this? 为什么是这样?

Seems like you want the grow class to be in the :host specificity? 似乎您希望grow类位于:host特定性中? If so, your CSS is wrong. 如果是这样,则您的CSS是错误的。

<style>
    :host {
        display: block;
    }
    :host.grow {
      min-height: 100%;
      height: 100%;
    }
</style>

The above should work. 以上应该可以。

I am using Polymer 1.6.0, and I have to use: 我正在使用Polymer 1.6.0,并且必须使用:

<style>
  :host {
     display: block;
  }
  :host(.grow) {
    min-height: 100%;
    height: 100%;
  }
</style>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM