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

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


当前回答

JavaScript方式:

使用字体.js你可以嵌入自定义 你的网页字体,这样你就不会 必须将文本渲染为图像 而不是创造图像或使用 Flash只是为了显示你的网站的图形 文本用你想要的字体,你可以使用 用纯HTML编写 和CSS,就像你的访问者一样 字体在本地安装。

http://typeface.neocracy.org/

其他回答

如果您使用ASP。NET,它很容易生成基于图像的字体,而不需要在服务器上安装(如添加到已安装的字体库)字体,通过使用:

PrivateFontCollection pfont = new PrivateFontCollection();
pfont.AddFontFile(filename);
FontFamily ff = pfont.Families[0];

然后用这种字体在图形上绘图。

也可以使用WOFF字体-例如这里

@font-face {
font-family: 'Plakat Fraktur';
src: url('/resources/fonts/plakat-fraktur-black-modified.woff') format('woff');
font-weight: bold;
font-style: normal;
 }

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

<!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>

它看起来只适用于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),所有常规浏览器都支持它。