回到另一个聚合物问题,我有一个聚合物/电子应用程序,我正在尝试设计。
我想创建一个theme.css
,其中包含一个:host
块,其中包含我的整个主题,然后我可以将其导入到我的模块样式表中,但我尝试了一些不同的东西并试图找到任何东西在文档中无济于事。
到目前为止,我已尝试过在<template>
定义之外的和:
<link rel="stylesheet" href="./account-list.css">
的 @import
<style>@import 'my-theme.css';</style>
就在<link>
之上
:root
:host
代替theme.css
但似乎都不起作用,theme.css
肯定是被要求的,但对模块的风格没有影响。
无论如何,聚合物都有这样的主题,我真的不希望有一个构建步骤。
答案 0 :(得分:5)
在Polymer 1.1中引入了一个名为样式模块(实际上是场景背后的dom-module
元素)的新概念(阅读它here)以及包含外部的旧方法样板已被弃用(请阅读here)。
基本上,您需要创建一个 html 文件,就像您通常创建一个元素来存储样式一样。 id
定义了稍后将引用的此文件的名称。
<!-- shared-styles.html -->
<dom-module id="shared-styles">
<template>
<style>
.red { color: red; }
</style>
</template>
</dom-module>
然后显然你需要在你的页面中导入这个文件。
<link rel="import" href="shared-styles.html">
现在,有两种情况。
答案 1 :(得分:2)
使用dom-module概念,并且为了使用外部第三方,我做了下一个并且它正在工作,但可能不是Polymer的最佳实践。
带有第三方css的Dom模块( third-party-styles.html )
<dom-module id="third-party-styles">
<link rel="stylesheet" href="../bower_components/thirdParty/external.css">
</dom-module>
我创建了一个容器( elements.html ),其中导入了所有需要的html模块,并且我在那里注册了第三方样式模块和我的模块
<link rel="import" href="third-party-styles.html">
<link rel="import" href="my-module.html">
我在 index.html
的头部添加了elements.html<head>
...
<link rel="import" href="elements.html">
<head>
<body>
<my-module></my-module>
</body>
在我的聚合物元素( my-module.html )
中<link rel="import" href="third-party-styles.html">
<dom-module id="my-module">
<style include="third-party-styles"></style>
<template>
<p class=".thirdPartyClass">Content with third party css rule</p>
</template>
</dom-module>
任何反馈?