gpt4 book ai didi

html - 如何在我的 html 网站上安装自定义字体

转载 作者:行者123 更新时间:2023-11-28 01:28:50 27 4
gpt4 key购买 nike

我在使用我网站上的 Cg Omega 字体时遇到问题。

这是我的 HTML:

<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="font.css">
<style type="text/css">
/* when @font-face is defined(it is in font.css) you can add the font to any rule by using font-family */
h1 {
font-family: 'cgomeg';
}
</style>
</head>
<body>
<h1>Lorem Ipsum</h1>
<p class="the-font">Lorem ipsum dolor sit amet</p>

这是我的 CSS:

@font-face {
font-family: 'cgomeg';
src: local('cgomeg'), url('cgomeg.ttf') format('truetype');
}


/* use this class to attach this font to any element i.e.
<p class="the-font">Text with this font applied</p> */
.the-font {
font-family: 'cgomeg' !important;
}

所有的代码似乎都是正确的,所有的文件都在正确的位置,我检查了三次。我还使用了一种不同的字体,这是我在 FontsForWeb.com 上找到的,那个可以用,但这个不行。我真的不知道我做错了什么,我需要专家的建议!

谢谢!

最佳答案

首先,你应该使用!important,它会很难继承类和做子规则,所以css规则应该是:

.the-font {
font-family: 'cgomeg';
}

此外,当你定义字体时,名称没有任何破折号,所以当你将它应用于 h1 时应该是:

h1 {
font-family: 'cgomeg';
}

注意:我假定字体与 .css 样式表位于同一文件夹中。

关于html - 如何在我的 html 网站上安装自定义字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31033182/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com