2013-07-05 55 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>