Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css 如何使用Polymer将自定义字体导入应用程序或元素?_Css_Polymer_Polymer 2.x - Fatal编程技术网

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

Css 如何使用Polymer将自定义字体导入应用程序或元素?,css,polymer,polymer-2.x,Css,Polymer,Polymer 2.x,如何将自定义字体导入聚合应用程序或元素 每@tweightman上的: :主持人{ @应用——我的自定义字体混合; } 偶然发现了一个可能的解决方案:我似乎不得不在my-typography.html样式模块中使用@font-face规则,而不是 在我的应用程序shell入口点(index.html)中,我有: @字体{ 字体系列:“空格Mono”,monospace; src:url(/fonts/SpaceMono-Regular.ttf)格式('truetype'); 字体大小:正常

如何将自定义字体导入聚合应用程序或元素

每@tweightman上的:


:主持人{
@应用——我的自定义字体混合;
}
偶然发现了一个可能的解决方案:我似乎不得不在my-typography.html样式模块中使用
@font-face
规则,而不是


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


@字体{
字体系列:“空格Mono”,monospace;
src:url(/fonts/SpaceMono-Regular.ttf)格式('truetype');
字体大小:正常;
字体风格:普通;
}
html{
--主字体系列:“空格Mono”,monospace;
}

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

有两种方法,可以通过html文件或自定义元素文件加载字体。每个人都知道如何在html文件中实现这一点,只需将链接添加到头部并在样式中使用即可

在自定义元素中,我们也会以不同的方式执行相同的操作。您可以使用构造函数ready()进行相同的操作

ready() {
super.ready();
const link = document.createElement("link");
link.rel = "stylesheet";
link.type = "text/css";
link.crossOrigin = "anonymous";
link.href =
  "https://fonts.googleapis.com/css?family=Megrim";
document.head.appendChild(link);

}

我正在尝试找到正确的实现方法,将新字体添加到聚合应用程序中,并用作默认字体。你能再详细说明一下你可能的解决办法吗?我的排版里有什么。html?@d.mares:我还没有解决方案。如果你有答案,请加上一个。即使它不起作用,至少它可能有助于产生一些想法。
<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>
ready() {
super.ready();
const link = document.createElement("link");
link.rel = "stylesheet";
link.type = "text/css";
link.crossOrigin = "anonymous";
link.href =
  "https://fonts.googleapis.com/css?family=Megrim";
document.head.appendChild(link);