我有一个自定义的Polymer元素,我想以某种特定的方式对其进行样式设置,并将其作为插件提供给许多不同的网站。我希望能够以一种封装自定义组件样式的方式来使它们在所有嵌入的网站上看起来都一样。下面是一个示例,显示了来自父Web页面的字体指令如何干扰我的组件样式:
<style>
* {
font-size: 18px;
}
</style>
<script src="http://www.polymer-project.org/webcomponents.js"></script>
<link rel="import" href="http://www.polymer-project.org/components/polymer/polymer.html">
<polymer-element name="polymer-css-test">
<template>
<style>
:host {
font-size: 12px;
}
</style>
<div>
Please tell me how to make this 12pt.
</div>
</template>
<script>
Polymer('polymer-css-test', {
ready: function () {
}
});
</script>
</polymer-element>
<polymer-css-test></polymer-css-test>
Thanks in advance for your help.
::shadow
或/deep/
。但是,有一些CSS属性(如font-size
)可以从父级继承,即使样式规则不适用于子元素本身。我认为这就是这里发生的事情。我承认这很奇怪,我找不到任何来源来证实我的理论。 - Timo D