【发布时间】:2018-04-08 22:30:26
【问题描述】:
我有一个 Polymer 2 应用,在加载任何组件之前明确指定了 --paper-font-common-base:
--paper-font-common-base: {
font-family: 'Comic Sans';
/* Not really, nobody's that evil, but problem is there for any font */
};
然后,在加载 Polymer 组件的某个时刻,例如 paper-dialog,将导入 typography.html
<link rel="import" href="../paper-styles/typography.html">
依次typography.htmlimports Roboto和overrides the mixin:
<link rel="import" href="../font-roboto/roboto.html">
...
<custom-style>
<style is="custom-style">
html {
--paper-font-common-base: {
font-family: 'Roboto', 'Noto', sans-serif;
-webkit-font-smoothing: antialiased;
};
这会覆盖我指定的字体,但也会从 Google's CDN 下载 Roboto,这是我明确不希望的。
其他 Polymer 组件,例如 paper-radio-button 采用不同的方法:
/*
This element applies the mixin `--paper-font-common-base` but does not import `paper-styles/typography.html`.
In order to apply the `Roboto` font to this element, make sure you've imported `paper-styles/typography.html`.
*/
如何设置 --paper-font-common-base 以便 Polymer 组件使用与我的应用程序其余部分相同的字体?
【问题讨论】:
-
我不确定,但
html, paper-dialog { --paper-...}还不够吗?只需在 html 之后添加 paper-dialog 即可将 css 直接应用于纸质对话框。另一种选择是在您以自己的风格定义`--paper-font-common-base`之前自行导入typography.html -
@KubaŠimonovský 无论如何它都会导入
typography.html,并且首先自己导入它仍然会添加在覆盖它们之前我不需要加载页面的请求。指定特定的控件并不能阻止这一点,即使我有所有这些的结论性列表。
标签: javascript css polymer polymer-2.x html-imports