【发布时间】:2015-03-28 00:59:31
【问题描述】:
首先,很抱歉关于这个主题的另一篇文章,但我在聚合物文档和 stackoverflow 上看不到任何对我有意义的内容。
我只想将样式附加到我的元素。
来自文档(https://www.polymer-project.org/0.5/articles/styling-elements.html 和 https://www.polymer-project.org/0.5/docs/polymer/styling.html#including-stylesheets-in-an-element)it 应该是直截了当的。
<polymer-element name="x-foo">
<template>
<style>
x-foo div { ... }
</style>
...
但它没有按预期工作。如果我们为元素定义样式,在元素内部,它不会被应用。
代码如下:
<polymer-element name="x-button" noscript>
<template>
<style>
/* not working */
x-button {
background-color: green;
}
/* not working */
x-button .hithere{
display: block;
min-height: 50px;
background-color: red;
margin: 20px;
}
/* not working */
x-button .hitheretoo{
display: block;
min-height: 50px;
background-color: blue;
margin: 20px;
}
</style>
<div class="hithere"></div>
<template>
<div class="hitheretoo"></div>
</template>
</template>
</polymer-element>
还有现场演示: http://codepen.io/anon/pen/yyZqMN
谢谢
【问题讨论】:
标签: css polymer web-component