0

我正在尝试使用 CSS 向我们的网站添加自定义字体:

body {
   background: #999999 url("../images/pattern29.png");
   color: #ffffff;
   font: 14px/25px Verdana, Verdana, sans-serif;
} 

但是每当我更改字体时,它都不起作用。我究竟做错了什么?

4

4 回答 4

2

尝试使用该@font-face属性添加您的自定义字体

@font-face
{
    font-family:"YourFontName";
    src:url("yourfont.ttf"),
        url("yourfont.eot"); 
    /*etc etc*/     
    font-weight:normal;
    font-style:normal;
}

然后,您可以通过使用 html 上的 font-family 属性来使用此字体

body
{
    font-family:"YourFontName",Verdana/*etc*/;
}
于 2013-08-17T22:26:26.017 回答
2

如果您需要自定义字体,请尝试使用 web fonts.CSS3 具有可以将字体加载到您的网页的 @font-face,Paul Irish 撰写的一篇关于 @font-face 的有用且有趣的文章:Bulletproof @font-face Syntax

@font-face 示例:

@font-face{
        font-family:MyFont;
        src:url(../font/MyFont.eot);
        src:local('?'),
            url(../font/MyFont.woff) format("woff"),
            url(../font/MyFont.otf) format("opentype"),
            url(../font/MyFont.ttf) format("Truetype"),
            url(../font/MyFont.svg#myfont) format("svg");
        }
body{
     font-family: "MyFont", Verdana, sans-serif; /* Font stack */
}
于 2013-08-17T22:37:21.923 回答
1

你需要先用@font-face 嵌入字体,然后你可以在你的css 中使用font-family: http ://www.w3schools.com/cssref/css3_pr_font-face_rule.asp

于 2013-08-17T22:23:06.357 回答
1

你应该看看FontSquirrel。他们有一个@font-face 生成器,它将为您格式化字体,因为我们将编写您需要在页面中包含字体的 CSS。

您还可以查看 Google 的网络字体 API。同样的交易,它们通过允许您添加标签使其变得更容易。

于 2013-08-17T22:42:15.987 回答