对于 webfonts(实际上是一般的任何字体),粗体、斜体和其他变体实际上是需要加载的单独文件。因此,如果您使用常规、粗体、斜体和粗斜体,则需要加载四个单独的文件。
谷歌字体
就像自托管一样,您必须明确告诉 Google 字体以获得您想要的所有权重和变体。您可以在获得嵌入代码的小框中执行此操作。单击“自定义”选项卡,然后选择所需的变体。
这里有一些例子。我在这里使用@import 选项,您只需将其放入样式表中,但标准link 标记的模式相同。
默认只包含常规权重:
@import url('https://fonts.googleapis.com/css?family=Noto+Serif');
如果你想要规则和粗体,它看起来像这样:
@import url('https://fonts.googleapis.com/css?family=Noto+Serif:400,700');
如果你想要这两个都用斜体,你也可以添加它们:
@import url('https://fonts.googleapis.com/css?family=Noto+Serif:400,400i,700,700i');
自托管
在您上面的代码中,在我看来您需要定义半粗体字体。如果上面的 CSS 是完整的,它只定义了常规的权重。半粗体版本的路径需要在另一个 @font-face 指令中定义,字体粗细设置不同。它应该看起来像这样:
@font-face {
font-family:'Noto Serif Lao';
src: url('fonts/Noto Serif Lao Regular.eot');
src: url('fonts/Noto Serif Lao Regular.eot?#iefix') format('embedded-opentype'),
url('fonts/Noto Serif Lao Regular.woff2') format('woff2'),
url('fonts/Noto Serif Lao Regular.woff') format('woff'),
url('fonts/Noto Serif Lao Regular.ttf') format('truetype'),
url('fonts/Noto Serif Lao Regular.svg#Noto Serif Lao Regular') format('svg');
font-weight: 400;
font-style: normal;
font-stretch: normal;
}
@font-face {
font-family:'Noto Serif Lao';
src: url('fonts/Noto Serif Lao Semibold.eot');
src: url('fonts/Noto Serif Lao Semibold.eot?#iefix') format('embedded-opentype'),
url('fonts/Noto Serif Lao Semibold.woff2') format('woff2'),
url('fonts/Noto Serif Lao Semibold.woff') format('woff'),
url('fonts/Noto Serif Lao Semibold.ttf') format('truetype'),
url('fonts/Noto Serif Lao Semibold.svg#Noto Serif Lao Semibold') format('svg');
font-weight: 700;
font-style: normal;
font-stretch: normal;
}
工作版本
谷歌字体
这个只使用常规和粗体,没有斜体。但是您可以设置@import 指令来引入项目所需的任何内容。请注意只加载您需要的内容,因为大量字体文件会降低您的网站速度。
@import url('https://fonts.googleapis.com/css?family=Noto+Serif:400,700');
@import url(//fonts.googleapis.com/earlyaccess/notosanslao.css);
@import url(//fonts.googleapis.com/earlyaccess/notoseriflao.css);
h1 { font-family: sans-serif; margin: 0; }
h1.noto { font-family: 'Noto Serif', sans-serif; font-weight: 400; }
h1.bold { font-weight: 700; }
h1.lao { font-family: 'Noto Serif Lao'; font-weight: 400; }
h1.lao-bold { font-family: 'Noto Serif Lao'; font-weight: 700; }
h1.sans-lao { font-family: 'Noto Sans Lao'; font-weight: 400; }
h1.sans-lao-bold { font-family: 'Noto Sans Lao'; font-weight: 700; }
<h1 class="lao">ຕົວອັກສອນລາວ</h1>
<h1 class="lao-bold">ຕົວອັກສອນລາວ</h1>
<h1 class="sans-lao">ຕົວອັກສອນລາວ</h1>
<h1 class="sans-lao-bold">ຕົວອັກສອນລາວ</h1>
<h1 class="noto">Noto Serif Lao</h1>
<h1 class="noto bold">Noto Serif Lao Semibold</h1>
自托管
对于自托管,我只指定了 TTF 版本,因为这就是您在上面提供的。我只是在这个演示中使用了 Dropbox 链接,但您可以将它们换成您的特定路径。如果您想包含其他字体格式(.woff、.svg 等),您需要确保为所有这些字体格式(无论是两种粗细)都有单独的文件。
font-face {
font-family:'Noto Serif Lao';
src: url('https://nwalton3.github.io/fonts/noto/noto-serif-lao/notoseriflao-regular-webfont.woff2') format('woff2'),
url('https://nwalton3.github.io/fonts/noto/noto-serif-lao/notoseriflao-regular-webfont.woff') format('woff');
font-weight: 400;
font-style: normal;
font-stretch: normal;
unicode-range: U+0E80-0EFF;
}
@font-face {
font-family:'Noto Serif Lao';
src: url('https://nwalton3.github.io/fonts/noto/noto-serif-lao/notoseriflao-bold-webfont.woff2') format('woff2'),
url('https://nwalton3.github.io/fonts/noto/noto-serif-lao/notoseriflao-bold-webfont.woff') format('woff');
font-weight: 700;
font-style: normal;
font-stretch: normal;
unicode-range: U+0E80-0EFF;
}
.lao {
font-family: 'Noto Serif Lao';
font-weight: 400;
}
.lao-bold {
font-family: 'Noto Serif Lao';
font-weight: 700;
}
<h1>No font: ຕົວອັກສອນລາວ</h1>
<h1 class="lao">Regular: ຕົວອັກສອນລາວ</h1>
<h1 class="lao-bold">Bold: ຕົວອັກສອນລາວ</h1>