it编程 > 网页制作 > html5

HTML5中使用Noto Sans CJK字体的详细步骤

300人参与 2024-09-23 html5

在html5中使用noto sans cjk字体的详细指南 

在网页设计中,字体选择对用户体验至关重要。noto sans cjk 是 google 提供的一个优秀的免费字体系列,支持中文简体、繁体以及日文字符,具有简洁现代的风格。本文将详细介绍如何在html5项目中使用 noto sans cjk 字体,包括在线加载和本地托管两种方式。

方法一:通过google fonts在线加载noto sans cjk

这种方法无需下载字体文件,直接通过 google fonts 提供的链接在线加载字体,非常方便。

步骤 1:访问google fonts并获取字体链接

步骤 2:获取字体的<link>标签

选择所需的字重(如常规、加粗),google fonts 会生成一个包含字体的 <link> 标签。例如,选择 noto sans sc,google fonts 生成如下链接:

<link href="https://fonts.googleapis.com/css2?family=noto+sans+sc:wght@400;700&display=swap" rel="stylesheet">

步骤 3:在html文件中引入字体

将复制的 <link> 标签添加到 html 文件的 <head> 部分中。然后在 css 中使用 font-family 应用字体:

<!doctype html>
<html lang="zh">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>使用 noto sans cjk 字体</title>
  <link href="https://fonts.googleapis.com/css2?family=noto+sans+sc:wght@400;700&display=swap" rel="stylesheet">
  <style>
    body {
      font-family: 'noto sans sc', sans-serif;
    }
  </style>
</head>
<body>
  <h1>这是 noto sans sc 字体的标题</h1>
  <p>这是使用 noto sans sc 字体的段落内容。</p>
</body>
</html>

这样,网页就会加载并使用 google fonts 提供的在线字体。

方法二:下载并本地托管noto sans cjk

如果你希望在本地项目中托管字体(例如,确保字体在没有网络连接时也能使用),可以下载字体文件并通过 @font-face 引入。

步骤 1:下载字体文件

前往 google noto fonts github,下载你需要的字体文件。根据需要选择语言版本:

将下载的字体文件保存在项目的 fonts 文件夹中,例如:

/project
  /fonts
    notosanssc-regular.otf

步骤 2:使用 @font-face 在css中加载字体

在你的 css 文件中通过 @font-face 引入字体文件:

@font-face {
  font-family: 'noto sans sc';
  src: url('fonts/notosanssc-regular.otf') format('opentype');
  font-weight: normal;
  font-style: normal;
}

步骤 3:在html文件中应用字体

接下来,在 html 文件的样式中引用该字体:

<!doctype html>
<html lang="zh">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>本地托管 noto sans cjk 字体</title>
  <style>
    @font-face {
      font-family: 'noto sans sc';
      src: url('fonts/notosanssc-regular.otf') format('opentype');
      font-weight: normal;
      font-style: normal;
    }
    body {
      font-family: 'noto sans sc', sans-serif;
    }
  </style>
</head>
<body>
  <h1>这是本地托管的 noto sans sc 字体标题</h1>
  <p>这是使用本地托管 noto sans sc 字体的段落内容。</p>
</body>
</html>

这种方法非常适合需要离线访问的项目,或者希望完全掌控字体加载的开发场景。

总结

通过本文,你学到了两种使用 noto sans cjk 字体的方法:

这两种方式都可以根据项目的具体需求来选择使用,让你能够轻松地为网页项目添加优美的中文和日文字体。

refer:

https://github.com/notofonts/noto-cjk

https://fonts.google.com/

https://fonts.google.com/specimen/roboto

到此这篇关于在html5中使用noto sans cjk字体的详细指南的文章就介绍到这了,更多相关html5 noto sans cjk字体内容请搜索代码网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持代码网!

(0)
打赏 微信扫一扫 微信扫一扫

您想发表意见!!点此发布评论

推荐阅读

HTML5表单的自动验证、取消验证、自定义错误信息的操作

09-23

HTML5中Checkbox标签详解

10-17

html5浏览器中实现高德地图定位功能(推荐)

10-22

详解HTML5元素定位

10-22

HTML5实现本地摄像头拍照与照片上传的方法

10-22

使用HTML5新增的表单元素来增强表单功能

10-23

猜你喜欢

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论