如果我在 css 中定义自定义外部字体,是否需要为每个使用它的类声明 src?

发布于 2024-12-24 19:24:46 字数 339 浏览 5 评论 0原文

如果我使用外部加载的字体(例如“MyFont”)并且它将在多个类中使用,我是否需要这样做:

.one { font-family: MyFont; src: url( "fonts/MyFont.ttf" ); }
.two { font-family: MyFont; src: url( "fonts/MyFont.ttf" ); }

或者我可以这样做吗?

.one { font-family: MyFont; src: url( "fonts/MyFont.ttf" ); }
.two { font-family: MyFont; }

If I am using an externally loaded font (e.g. "MyFont") and it's going to be used in multiple classes, do I need to do this:

.one { font-family: MyFont; src: url( "fonts/MyFont.ttf" ); }
.two { font-family: MyFont; src: url( "fonts/MyFont.ttf" ); }

or can I do this?

.one { font-family: MyFont; src: url( "fonts/MyFont.ttf" ); }
.two { font-family: MyFont; }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情何以堪。 2024-12-31 19:24:46

不,请查看这篇文章:新的 Bulletproof @Font-Face 语法

在 CSS 文件的开头添加类似的内容:

@font-face {
    font-family: 'MyFontFamily';
    src: url('myfont-webfont.eot?#iefix') format('embedded-opentype'), 
         url('myfont-webfont.woff') format('woff'), 
         url('myfont-webfont.ttf')  format('truetype'),
         url('myfont-webfont.svg#svgFontName') format('svg');
    }

使用此示例代码运行,CSS 的其余部分应如下所示:

.one { font-family: MyFontFamily }
.two { font-family: MyFontFamily }

No, check out this article: The New Bulletproof @Font-Face Syntax

Add something like this at the beginning of your CSS file:

@font-face {
    font-family: 'MyFontFamily';
    src: url('myfont-webfont.eot?#iefix') format('embedded-opentype'), 
         url('myfont-webfont.woff') format('woff'), 
         url('myfont-webfont.ttf')  format('truetype'),
         url('myfont-webfont.svg#svgFontName') format('svg');
    }

Running with this sample code, the rest of your CSS should look something like:

.one { font-family: MyFontFamily }
.two { font-family: MyFontFamily }
心如荒岛 2024-12-31 19:24:46

您应该使用 @font-face 指令。

@font-face {
    font-family: MyFont;
    src: url(...);
}

.one { font-family: MyFont; }
.two { font-family: MyFont; }

You should use @font-face directive.

@font-face {
    font-family: MyFont;
    src: url(...);
}

.one { font-family: MyFont; }
.two { font-family: MyFont; }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文