[英]How do I install a custom font on my html site
我在我的網站上使用字體 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樣式表位於同一文件夾中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.