css - 如何使用 Polymer 将自定义字体导入应用程序或元素?

标签 css polymer polymer-2.x

如何将自定义字体导入 Polymer 应用或元素?

@tweightman 在 Polymer Slack Channel 上:

<link rel="import" href="/bower_components/polymer/polymer-element.html">
<link rel="import" href="/bower_components/my-typography/my-typography.html">

<dom-module id="my-page-styles">
  <template>
    <style include="my-typography">
      :host {
        @apply --my-custom-font-mixin;
      }
    </style>
  </template>
</dom-module>

Stumbled across a possible solution: instead of using @font-face rules inside my-typography.html style module, I seem to have to <link rel="stylesheet" href="my-font-face.css"> instead.

最佳答案

在我的应用程序 shell 入口点 ( index.html ) 中,我有:

<custom-style>
    <style is="custom-style">
        @font-face {
            font-family: 'Space Mono', monospace;
            src: url(/fonts/SpaceMono-Regular.ttf) format('truetype');
            font-weight: normal;
            font-style: normal;
        }

        html {
            --primary-font-family: 'Space Mono', monospace;
        }
    </style>
</custom-style>

然后我就像在其他地方一样使用该字体,或者 var(--primary-font-family)或者就像 font-family: 'Space Mono' .

关于css - 如何使用 Polymer 将自定义字体导入应用程序或元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44634451/

相关文章:

data-binding - 从 Polymer 0.5 迁移到 1.0 后属性发生更改时 DOM 不会更新

css - 如何使用纸卡创建网格布局

polymer - 如何结合 polymer-redux 和 <app-route>?

unity-game-engine - 确保 polymer 构建过程不会干扰我的元素的依赖性

jquery - 如何在禁用的单选按钮悬停时显示文本?

jquery 移动复选框未被选中

polymer-2.x - 获取铁页中的页数

javascript - 将参数传递给类

html - div 上的撕边模式?

html - 基本 CSS 定位