SCSS的解决方案:
@mixin fontPoppins($name, $weight, $style) {
@font-face {
font-family: poppins;
src: url('/assets/poppins/#{$name}.ttf') format("truetype");
font-weight: $weight;
font-style: $style;
}
}
@include fontPoppins('Poppins-Thin', 100, normal);
@include fontPoppins('Poppins-ThinItalic', 100, italic);
@include fontPoppins('Poppins-ExtraLight', 200, normal);
@include fontPoppins('Poppins-ExtraLightItalic', 200, italic);
@include fontPoppins('Poppins-Light', 300, normal);
@include fontPoppins('Poppins-LightItalic', 300, italic);
@include fontPoppins('Poppins-Regular', normal, normal);
@include fontPoppins('Poppins-Italic', normal, italic);
@include fontPoppins('Poppins-Medium', 500, normal);
@include fontPoppins('Poppins-MediumItalic', 500, italic);
@include fontPoppins('Poppins-SemiBoldItalic', 600, italic);
@include fontPoppins('Poppins-Bold', bold, normal);
@include fontPoppins('Poppins-BoldItalic', bold, italic);
@include fontPoppins('Poppins-ExtraBold', 800, normal);
@include fontPoppins('Poppins-ExtraBoldItalic', 800, italic);
@include fontPoppins('Poppins-Black', 900, normal);
@include fontPoppins('Poppins-BlackItalic', 900, italic);
在 Angular 中,字体文件被期望存放在 assets 文件夹中,而不是某个静态文件夹。
目前我在 assets 文件夹中有 18 个从 Google Fonts 下载的文件。
Poppins-Black.ttf
Poppins-BlackItalic.ttf
Poppins-Bold.ttf
Poppins-BoldItalic.ttf
Poppins-ExtraBold.ttf
Poppins-ExtraBoldItalic.ttf
Poppins-ExtraLight.ttf
Poppins-ExtraLightItalic.ttf
Poppins-Italic.ttf
Poppins-Light.ttf
Poppins-LightItalic.ttf
Poppins-Medium.ttf
Poppins-MediumItalic.ttf
Poppins-Regular.ttf
Poppins-SemiBold.ttf
Poppins-SemiBoldItalic.ttf
Poppins-Thin.ttf
Poppins-ThinItalic.ttf
接下来是什么?
或将其添加到全局CSS文件中
@tailwind base;
@tailwind components;
@tailwind utilities;
body { margin: 0; }
html, body {
height: 100%;
font-family: poppins, sans-serif ;
}
或者在HTML中使用
在HTML中的某处使用style属性:
<p style='font-family: poppins, sans-serif;
font-weight: bold;
font-style: italic' >Some text</p>
在互联网问题的情况下,"sans-serif"是备用字体。
或者在Tailwind中使用它。
<p style='font-family: poppins, sans-serif'
class='font-bold italic'>Some text</p>