如何通过CSS将字体应用于网站

如何通过CSS将字体应用于网站,css,fonts,Css,Fonts,我正在尝试使用CSS向我们的网站添加自定义字体: body { background: #999999 url("../images/pattern29.png"); color: #ffffff; font: 14px/25px Verdana, Verdana, sans-serif; } 但是每当我改变字体时,它就不起作用了。我做错了什么?您需要先将字体嵌入@font-face,然后才能在您的css字体系列中使用它: 您需要先将字体嵌入到@font-face中,然后才

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

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

但是每当我改变字体时,它就不起作用了。我做错了什么?

您需要先将字体嵌入@font-face,然后才能在您的css字体系列中使用它:

您需要先将字体嵌入到@font-face中,然后才能在css和字体系列中使用它:

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

@font-face
{
    font-family:"YourFontName";
    src:url("yourfont.ttf"),
        url("yourfont.eot"); 
    /*etc etc*/     
    font-weight:normal;
    font-style:normal;
}
然后,可以通过在html上使用字体族属性来使用此字体

body
{
    font-family:"YourFontName",Verdana/*etc*/;
}

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

@font-face
{
    font-family:"YourFontName";
    src:url("yourfont.ttf"),
        url("yourfont.eot"); 
    /*etc etc*/     
    font-weight:normal;
    font-style:normal;
}
然后,可以通过在html上使用字体族属性来使用此字体

body
{
    font-family:"YourFontName",Verdana/*etc*/;
}

如果您需要自定义字体,请尝试web fonts.CSS3的@font-face可以将字体加载到您的网页中, Paul Irish关于@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 */
}

如果您需要自定义字体,请尝试web fonts.CSS3的@font-face可以将字体加载到您的网页中, Paul Irish关于@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 */
}
你应该看一看。他们有一个@font-face生成器,它将为您格式化字体,因为我们将编写CSS,您需要在页面中包含字体

你也可以看看谷歌的网页字体API。同样的交易,他们让你只需要添加一个标签就可以了

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


你也可以看看谷歌的网页字体API。同样的交易,他们让你只需要添加一个标签就可以了

你说改变字体是什么意思?您是否将其包含在
@font-face
中?更改字体是什么意思?您是否将其包含在
@font-face
中?