跳转到内容

如何在网站上使用自己的字体 ​

你需要可以修改网站代码

步骤总览 ​

$$ 上传你的字体文件至某处 \longrightarrow 在CSS中引入字体 \longrightarrow 在某处使用它 $$

详细步骤 ​

将你的字体文件上传至某处 ​

假设字体文件位于网站根目录下的fonts/custom-font-regular.ttf。

在CSS中引入字体 ​

在网站的样式中添加以下代码:

css
/* 第一个字体 */
@font-face {
    font-family: 'CustomFontRegular';
    src: url('fonts/custom-font-regular.ttf') format('truetype');
}

/* 第二个字体
@font-face {
    font-family: 'CustomFontBold';
    src: url('fonts/custom-font-bold.ttf') format('truetype');
    font-weight: bold; // 如果这是粗体字体,需要显式指定 //
}
*/

/* 需要显式指定的有:
- font-weight (font-weight: bold; 显式指定粗体)
- font-style (font-style: italic; 显式指定斜体)
- unicode-range (unicode-range: U+0000-00FF; 仅支持基本拉丁字符集)
*/

在某处使用它 ​

For example:

css
body {
    font-family: 'CustomFontRegular', Arial, sans-serif; /* 使用修改后的字体名称 */
}