有没有一种方法可以在网站上添加一些自定义字体,而不使用图像,Flash或其他图形?

例如,我在一个婚礼网站上工作,我为这个主题找到了很多漂亮的字体。但是我找不到在服务器上添加那种字体的正确方法。我如何将CSS字体包含到HTML中?如果没有图像,这可能吗?


当前回答

《IE中的字体面:让Web字体正常工作》一文中说,它适用于所有三种主要浏览器。

这是我得到的一个工作样本:http://brendanjerwin.com/test_font.html

更多的讨论在嵌入字体中。

其他回答

它看起来只适用于ie浏览器,但是在谷歌上快速搜索“html嵌入字体”会得到http://www.spoono.com/html/tutorials/tutorial.php?id=19

如果你想保持平台无关性(你应该!),你就必须使用图像,或者使用标准字体。

这可以通过CSS来完成:

<style type="text/css">
@font-face {
    font-family: "My Custom Font";
    src: url(http://www.example.org/mycustomfont.ttf) format("truetype");
}
p.customfont { 
    font-family: "My Custom Font", Verdana, Tahoma;
}
</style>
<p class="customfont">Hello world!</p>

如果你使用TrueType-Fonts (TTF), Web Open Font Format (WOFF)或Embedded Opentype (EOT),所有常规浏览器都支持它。

如果您有一个字体文件,那么您将需要为其他浏览器添加该字体的更多格式。

出于这个目的,我使用Fontsquirrel这样的字体生成器,它提供了所有的字体格式和它的@font-face CSS,你只需要将它拖放到你的CSS文件中。

简单的解决方法是在CSS中使用@fontface

@font-face {
font-family: myFirstFont;
src: url(fileLocation);} 

div{
    font-family: myfirstfont;}

只需简单地提供链接到实际的字体像这样,你就会很好

<!DOCTYPE html>
<html>
<head>
<link href='https://fonts.googleapis.com/css?family=Montserrat'   rel='stylesheet'>
<style>
body {
font-family: 'Montserrat';font-size: 22px;
}
</style>
</head>
<body>

<h1>Montserrat</h1>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</p>


</body>
</html>