【发布时间】:2017-04-01 06:42:55
【问题描述】:
我有一个shared-styles 元素,它可以保留我的大部分应用程序颜色。我可以轻松地在shared-styles.html 中手动更改颜色,如果我使用 CSS 变量,我的所有其他组件都可以从那里继承。
我的问题是我需要更新 shared-styles.html 中的 CSS 变量,并让所有其他继承 CSS 变量的组件相应地更新它们的颜色。下面是我的shared-styles.html。为简洁起见,我删除了除 --app-primary-color 之外的所有变量。
<link rel="import" href="../bower_components/polymer/polymer-element.html">
<!-- shared styles for all views -->
<dom-module id="shared-styles">
<template>
<style is="custom-style">
:host {
--app-primary-color:#2196F3;
}
</style>
</template>
<script>
class SharedStyles extends Polymer.Element {
static get is() { return 'shared-styles'; }
ready(){
super.ready();
console.log('update css');
this.updateStyles({'--app-primary-color': 'red'});
}
}
window.customElements.define(SharedStyles.is, SharedStyles);
</script>
</dom-module>
这就是我将它们包含在其他组件中的方式。例如:
<dom-module id="test-element">
<template>
<style include="shared-styles">
【问题讨论】:
标签: css polymer polymer-2.x