从外部样式表中导入聚合物元素的样式

时间:2017-05-11 12:21:32

标签: html5 css3 polymer polymer-2.x

我正在使用聚合物目录中的聚合物paper-card元素。

我可以使用以下命令从我的html文件中指定mixin:

<style is="custom-style">
paper-card {
  width:300px; 
  --paper-card-header:{width:200px;
  height: 200px;
  margin: 25px auto;
  border-radius: 200px;
};
}
</style>

如何从外部样式表指定相同的样式?我不想更改paper-card.html导入文件的内容。

感谢。

1 个答案:

答案 0 :(得分:1)

要在外部样式表中包含组件的样式,您可以执行以下操作:

  • 如果样式表是CSS文件,只需像导入任何其他样式表一样导入它。 已弃用

  • 您可以使用与创建自定义Polymer组件相同的方式创建样式表:

<dom-module id="global-styles">
  <template>
    <style>
      .card {
        // Your styles go here as normal
      }
    </style>
  </template>
</dom-module>

将其导入要将其应用于的聚合物组件:

<link rel="import" href="../path/to/my/external/styles">
<dom-module id="some-other-component">
  <template>
    <style include="global-styles"></style>
      <style>
        //Some more styles
      </style>
  </template>
</dom-module>

有关此问题以及具体指南/规则的更多信息,请check out the Polymer Docs on this!