我最近偶然发现了@font-family CSS规则,因为我希望在我的网站上使用网页字体。
说到点子上,我在@font-family CSS代码中看到了两种变体,如下所示:
@font-face {
font-family: 'Droid Serif'; /* NOTE THIS LINE */
font-weight: normal; /* NOTE THIS LINE */
font-style: normal; /* NOTE THIS LINE */
src: url('DroidSerif-Regular-webfont.eot');
src: url('DroidSerif-Regular-webfont.eot?#iefix') format('embedded-opentype'),
local('Droid Serif'), local('DroidSerifRegular'),
url('DroidSerif-Regular-webfont.woff') format('woff'),
url('DroidSerif-Regular-webfont.ttf') format('truetype'),
url('DroidSerif-Regular-webfont.svg#DroidSerifRegular') format('svg');
}
@font-face {
font-family: 'Droid Serif'; /* NOTE THIS LINE */
font-weight: normal; /* NOTE THIS LINE */
font-style: italic; /* NOTE THIS LINE */
src: url('DroidSerif-Italic-webfont.eot');
src: url('DroidSerif-Italic-webfont.eot?#iefix') format('embedded-opentype'),
local('Droid Serif'), local('DroidSerifItalic'),
url('DroidSerif-Italic-webfont.woff') format('woff'),
url('DroidSerif-Italic-webfont.ttf') format('truetype'),
url('DroidSerif-Italic-webfont.svg#DroidSerifItalic') format('svg');
}这是另一个:
@font-face {
font-family: 'DroidSerifRegular'; /* NOTE THIS LINE */
font-weight: normal; /* NOTE THIS LINE */
font-style: normal; /* NOTE THIS LINE */
src: url('DroidSerif-Italic-webfont.eot');
src: url('DroidSerif-Italic-webfont.eot?#iefix') format('embedded-opentype'),
local('Droid Serif'), local('DroidSerifItalic'),
url('DroidSerif-Italic-webfont.woff') format('woff'),
url('DroidSerif-Italic-webfont.ttf') format('truetype'),
url('DroidSerif-Italic-webfont.svg#DroidSerifItalic') format('svg');
}
@font-face {
font-family: 'DroidSerifItalic'; /* NOTE THIS LINE */
font-weight: normal; /* NOTE THIS LINE */
font-style: normal; /* NOTE THIS LINE */
src: url('DroidSerif-Italic-webfont.eot');
src: url('DroidSerif-Italic-webfont.eot?#iefix') format('embedded-opentype'),
local('Droid Serif'), local('DroidSerifItalic'),
url('DroidSerif-Italic-webfont.woff') format('woff'),
url('DroidSerif-Italic-webfont.ttf') format('truetype'),
url('DroidSerif-Italic-webfont.svg#DroidSerifItalic') format('svg');
}将我用/* NOTE THIS LINE */注释的代码行进行比较
第一个变体是Google Web Fonts,第二个变体是Font Squirrel。那么,是这两个人中的一个错了吗?(只是想确认一下,尽管这两个都是非常可靠的来源。)
如果可以接受,我会选择两个中的哪一个更好?
发布于 2012-04-28 23:45:59
第一个例子,虽然很难相信,但却是正确的;注意Droid Serif Regular如何被声明为字体粗细normal,以及您期望显示的常规字体的样式normal...how。第二个声明是调用Droid Serif Italic,并将其设置为font-style:italic;这允许您在一个系列中使用多种字体。如果您想添加粗体字体,您将应用相同的@ font -face规则,除非您更改font-weight: bold,而保留font-style:normal并声明相同的字体系列。
fontsquirrel在渲染@font-face规则方面确实做得很好,实际上我在那里读到过这项技术。令人惊讶的是它没有被实现。你可以在这里阅读更多信息:http://www.456bereastreet.com/archive/201012/font-face_tip_define_font-weight_and_font-style_to_keep_your_css_simple/
https://stackoverflow.com/questions/10364458
复制相似问题