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

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


当前回答

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

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

其他回答

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

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

div{
    font-family: myfirstfont;}

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

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

这可以通过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),所有常规浏览器都支持它。

@font-face {
font-family: "CustomFont";
src: url("CustomFont.eot");
src: url("CustomFont.woff") format("woff"),
url("CustomFont.otf") format("opentype"),
url("CustomFont.svg#filename") format("svg");
}

我做了一些研究,找到了动态文本替换(发布于2004-06-15)。

这项技术使用图像,但它似乎是“解放双手”。您编写文本,然后让一些自动脚本在页面上自动执行查找和替换操作。

它有一些限制,但它可能是我所见过的最简单的选择之一(而且更兼容浏览器)。