2013-07-05 43 views
0

我想在我的網站的HTML中使用自定義字體。我應該怎麼做才能使用戶正確地查看它們,無論他們是否已將其安裝在PC中?HTML自定義字體

在此先感謝!

回答

0

您可以添加Google字體api

<html> 
    <head> 
    <link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Tangerine"> 
    <style> 
    body { 
     font-family: 'Tangerine', serif; 
     font-size: 48px; 
    } 
    </style> 
    </head> 
<body> 
    <div>Making the Web Beautiful!</div> 
</body> 
</html> 

這裏的細節Google fonts

0

你正在寫類似下面的段落,加style="font-family: Verdana"第一標籤:

<html> 
<body> 
    <p style="font-family: Verdana">This is a paragraph</p> 
</body> 
</html> 
0

<html> 
 
<head> 
 
<style> 
 
@font-face { 
 
    font-family:Elivio; 
 
    font-size:100px; 
 
    src: url('KittenSwashMonolineTrial.ttf'); 
 
div{ 
 

 
    font-family:Elivio; 
 

 
} 
 
</style> 
 

 
</head> 
 
<body> 
 
<div style="font-family:Elivio;">Elivio is a FAMILY ORGANIZER. 
 
An integrated system for family ,giving solutions for our day to day planning activities. It's an account for the whole family that keeps our family members together<a href="https://www.elivio.com">elivio for family</a> 
 
</div> 
 
<h1 style="font-family:Elivio;"> 
 
Elivio</h1> 
 
</body> 
 

 

 
</html>

+0

至少把一些解釋你的答案。在這種情況下,@ font-face的描述會很好。 – thepio

-1

@font-face { 
 
    body { 
 
    font-family: 'Elivo', sans-serif; 
 
} 
 
div{ 
 

 
    font-family:Elivio; 
 

 
}

0

最簡單的方法是使用谷歌字體。這裏有一段代碼展示了它是如何完成的。

body { 
 
    font-family: 'Oswald', sans-serif; 
 
}
<html> 
 
    <head> 
 
    <link href='https://fonts.googleapis.com/css?family=Oswald' rel='stylesheet' type='text/css'> 
 
    </head> 
 
    <body> 
 
    <div> 
 
     <h1>Lorem ipsum dolor sit amet</h1> 
 
     <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p> 
 
    </div> 
 
</body> 
 
</html>

在上面的代碼,你指的是谷歌的字體在您的標題是這樣的:

<link href='https://fonts.googleapis.com/css?family=Oswald' rel='stylesheet' type='text/css'> 

你可以在這裏找到不同的谷歌字體:https://www.google.com/fonts

而且只需在你的CSS中設置字體如下:

body { 
    font-family: 'Oswald', sans-serif; 
} 

您可以將您的字體設置爲頁面上的任何元素或像我的示例中的身體一樣,將其放在所有元素上。

谷歌字體包括這些字體到您的網頁@font-face

@ font-face CSS at-rule允許作者指定聯機字體以在其網頁上顯示文本。通過允許作者提供他們自己的字體,@ font-face消除了依靠用戶在其計算機上安裝的有限字體數量的需要。 @ font-face at-rule不僅可以用於CSS的頂層,也可以用於任何CSS條件組at-rule。

您可以在MDN documentation

@font-face { 
    font-family: 'Oswald'; 
    font-style: normal; 
    font-weight: 400; 
    src: local('Oswald Regular'), local('Oswald-Regular'), url(https://fonts.gstatic.com/s/oswald/v11/yg0glPPxXUISnKUejCX4qfesZW2xOQ-xsNqO47m55DA.woff2) format('woff2'); 
    unicode-range: U+0100-024F, U+1E00-1EFF, U+20A0-20AB, U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF; 
} 

@font-face { 
    font-family: 'Oswald'; 
    font-style: normal; 
    font-weight: 400; 
    src: local('Oswald Regular'), local('Oswald-Regular'), url(https://fonts.gstatic.com/s/oswald/v11/pEobIV_lL25TKBpqVI_a2w.woff2) format('woff2'); 
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215, U+E0FF, U+EFFD, U+F000; 
} 

找到更多的信息,你也可以有自己的自定義字體(文件)在您的項目,只是設置源URL指向到何地你的字體。使用自定義字體的

1

<html> 
 
<head> 
 
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Tangerine"> 
 

 
<style> 
 
@font-face { 
 
    font-family:'Elivio',sans-serif; 
 
    font-size:100px; 
 
div{ 
 

 
    font-family:Elivio; 
 

 
} 
 
</style> 
 

 
</head> 
 
<body> 
 
<div style="font-family:Elivio;">Elivio is a FAMILY ORGANIZER. 
 
An integrated system for family ,giving solutions for our day to day planning activities. It's an account for the whole family that keeps our family members together<a href="https://www.elivio.com">elivio for family</a> 
 
</div> 
 
<h1 style="font-family:Elivio;"> 
 
Elivio</h1> 
 
</body> 
 

 

 
</html>

0

<html> 
 
<head> 
 
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Tangerine"> 
 

 
<style> 
 
@font-face { 
 
    font-family:'Elivio',sans-serif; 
 
    font-size:100px; 
 
div{ 
 

 
    font-family:Elivio; 
 

 
} 
 
</style> 
 

 
</head> 
 
<body> 
 
<div style="font-family:Elivio;">Elivio is a FAMILY ORGANIZER. 
 
An integrated system for family ,giving solutions for our day to day planning activities. It's an account for the whole family that keeps our family members together<a href="https://www.elivio.com"> elivio for family</a> 
 
</div> 
 
<h1 style="font-family:Elivio;"> 
 
<a href="https://elivio.com">Elivio</a> </h1> 
 
</body> 
 

 

 
</html>

0

這裏示例(如Elivio):

<html> 
 
<head> 
 
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Tangerine"> 
 

 
<style> 
 
@font-face { 
 
    font-family:'Elivio',sans-serif; 
 
    font-size:100px; 
 
div{ 
 

 
    font-family:Elivio; 
 

 
} 
 
</style> 
 

 
</head> 
 
<body> 
 
<div style="font-family:Elivio;">Elivio is a FAMILY ORGANIZER. 
 
An integrated system for family ,giving solutions for our day to day planning activities. It's an account for the whole family that keeps our family members together<a href="https://www.elivio.com"> elivio App or site for family best for ever</a> 
 
</div> 
 
<h1 style="font-family:Elivio;"> 
 
<a href="https://elivio.com" target="_blank">Elivio</a> </h1> 
 
</body> 
 

 

 
</html>

<html> 
 
<head> 
 
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Tangerine"> 
 

 
<style> 
 
@font-face { 
 
    font-family:'Elivio',sans-serif; 
 
    font-size:100px; 
 
div{ 
 

 
    font-family:Elivio; 
 

 
} 
 
</style> 
 

 
</head> 
 
<body> 
 
<div style="font-family:Elivio;">Elivio is a FAMILY ORGANIZER. 
 
An integrated system for family ,giving solutions for our day to day planning activities. It's an account for the whole family that keeps our family members together<a href="https://www.elivio.com"> elivio for family</a> 
 
</div> 
 
<h1 style="font-family:Elivio;"> 
 
<a href="https://elivio.com">Elivio</a> </h1> 
 
</body> 
 

 

 
</html>