CSS

步骤

  1. 下载字体文件:首先,从合法的来源下载所需的字体文件(通常为.ttf、.otf、.woff等格式),并保存到本地项目目录中。

  2. 在CSS文件中导入字体:在CSS文件中使用@font-face规则来引入本地字体。例如:

@font-face {
    font-family: 'CustomFont';
    src: url('path/to/fontFile.ttf') format('truetype');
    /* 可以根据需要添加其他属性 */
}

示例

<!DOCTYPE html>
<html>
<head>
    <style>
        @font-face {
            font-family: "CustomFont";
            src: url("path/to/font.ttf") format("truetype");
        }
 
        body {
            font-family: "CustomFont", sans-serif;
        }
    </style>
</head>
<body>
    <p>This text will be displayed in the custom font imported from a local file.</p>
</body>
</html>