css - 如何简化CSS中的字体导入

标签 css fonts

我有一个名为 SourceSansPro 的字体,我将它包含在我的 css 中,如下所示:

@font-face {
    font-family: "SourceSansPro";
    src: url("../font/SourceSansPro-Bold.otf");
    font-weight: bold;
    font-style: normal;
}

@font-face {
    font-family: "SourceSansPro";
    src: url("../font/SourceSansPro-Regular.otf");
    font-weight: normal;
    font-style: normal;
}

@font-face {
    font-family: "SourceSansPro";
    src: url("../font/SourceSansPro-Light.otf.otf");
    font-weight: lighter;
    font-style: normal;
}

这有点多余。有没有更简洁的方法来做到这一点?

最佳答案

不幸的是@font-face 语法不是很灵活。在这种情况下,您将受到浏览器开发人员的摆布。但是,您可以将字体分段到 fonts.css 文件中,然后进行导入:

@import url('css/fonts.css');

另一种可能的解决方案是通过 Google's Font API 添加字体.这样一来,您就不必首先担心 CSS。你只需添加

@import url(http://fonts.googleapis.com/css?family=Source+Sans+Pro);

到你的样式表。或者你可以添加

<link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro' rel='stylesheet' type='text/css'>

<head>您的文档。

关于css - 如何简化CSS中的字体导入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17772945/

相关文章:

iphone - 内存使用随着 CTFontCreateWithName 和 CTFramesetterRef 的增加而增长

android - indic-text-renderer 使用 harfbuzz 和 freetype

css - MailKit 中 HTML 电子邮件正文的字体更改和样式

javascript - Masonry js 总是打开一些排水沟

php - 滚动时,Twitter Bootstrap Modal 窗口不会保持在屏幕中央

Jquery Li 图片库

php - 无法将 nav-below 定位在我的内容下方

html - flexbox 边距导致溢出

Android 动态壁纸因自定义字体而崩溃

html - 如何让字体光标位于顶部,文本对齐: top?