300人参与 • 2024-09-23 • html5
在网页设计中,字体选择对用户体验至关重要。noto sans cjk 是 google 提供的一个优秀的免费字体系列,支持中文简体、繁体以及日文字符,具有简洁现代的风格。本文将详细介绍如何在html5项目中使用 noto sans cjk 字体,包括在线加载和本地托管两种方式。
这种方法无需下载字体文件,直接通过 google fonts 提供的链接在线加载字体,非常方便。
选择所需的字重(如常规、加粗),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">
将复制的 <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 提供的在线字体。
如果你希望在本地项目中托管字体(例如,确保字体在没有网络连接时也能使用),可以下载字体文件并通过 @font-face
引入。
前往 google noto fonts github,下载你需要的字体文件。根据需要选择语言版本:
将下载的字体文件保存在项目的 fonts
文件夹中,例如:
/project /fonts notosanssc-regular.otf
在你的 css 文件中通过 @font-face
引入字体文件:
@font-face { font-family: 'noto sans sc'; src: url('fonts/notosanssc-regular.otf') format('opentype'); font-weight: normal; font-style: normal; }
接下来,在 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 字体的方法:
@font-face
引入字体,适合离线或对字体加载有更高控制要求的项目。这两种方式都可以根据项目的具体需求来选择使用,让你能够轻松地为网页项目添加优美的中文和日文字体。
refer:
https://github.com/notofonts/noto-cjk
https://fonts.google.com/specimen/roboto
到此这篇关于在html5中使用noto sans cjk字体的详细指南的文章就介绍到这了,更多相关html5 noto sans cjk字体内容请搜索代码网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持代码网!
您想发表意见!!点此发布评论
版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。
发表评论