【发布时间】:2013-09-25 17:32:28
【问题描述】:
有人可以帮助我了解使用 CSS3 字体的正确方法是什么。下面是一些 font-face 声明,哪一个是正确的,为什么?
/* START OF SAMPLE CODE # 1 */
@font-face {
font-family: 'WebFont';
src: url('webfont.eot');
src: url('webfont.eot?#iefix') format('embedded-opentype'),
url('webfont.woff') format('woff'),
url('webfont.ttf') format('truetype'),
url('webfont.svg#WebFont') format('svg');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: 'WebFont';
src: url('webfont-bold.eot');
src: url('webfont-bold.eot?#iefix') format('embedded-opentype'),
url('webfont-bold.woff') format('woff'),
url('webfont-bold.ttf') format('truetype'),
url('webfont-bold.svg#WebFont-Bold') format('svg');
font-weight: bold;
font-style: normal;
}
h1 {
font-family: 'WebFont', blah, blah, blah;
font-weight: bold;
}
h2 {
font-family: 'WebFont', blah, blah, blah;
font-weight: normal;
}
/* END OF SAMPLE CODE # 1 */
=========
/* START OF SAMPLE CODE # 2 */
@font-face {
font-family: 'WebFont';
src: url('webfont.eot');
src: url('webfont.eot?#iefix') format('embedded-opentype'),
url('webfont.woff') format('woff'),
url('webfont.ttf') format('truetype'),
url('webfont.svg#WebFont') format('svg');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: 'WebFontBold';
src: url('webfont-bold.eot');
src: url('webfont-bold.eot?#iefix') format('embedded-opentype'),
url('webfont-bold.woff') format('woff'),
url('webfont-bold.ttf') format('truetype'),
url('webfont-bold.svg#WebFont-Bold') format('svg');
font-weight: normal;
font-style: normal;
}
h1 {
font-family: 'WebFontBold', blah, blah, blah;
font-weight: normal;
}
h2 {
font-family: 'WebFont', blah, blah, blah;
font-weight: normal;
}
/* END OF SAMPLE CODE # 2 */
=========
/* START OF SAMPLE CODE # 3 */
@font-face {
font-family: 'WebFont';
src: url('webfont.eot');
src: url('webfont.eot?#iefix') format('embedded-opentype'),
url('webfont.woff') format('woff'),
url('webfont.ttf') format('truetype'),
url('webfont.svg#WebFont') format('svg');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: 'WebFontBold';
src: url('webfont-bold.eot');
src: url('webfont-bold.eot?#iefix') format('embedded-opentype'),
url('webfont-bold.woff') format('woff'),
url('webfont-bold.ttf') format('truetype'),
url('webfont-bold.svg#WebFont-Bold') format('svg');
font-weight: bold;
font-style: normal;
}
h1 {
font-family: 'WebFontBold', blah, blah, blah;
font-weight: bold;
}
h2 {
font-family: 'WebFont', blah, blah, blah;
font-weight: normal;
}
/* END OF SAMPLE CODE # 3 */
这些代码示例的不同之处在于声明和使用“粗体”字体的方式。请指教,这些中哪一个是正确的,为什么?
PS:对于这么长的问题/示例,我深表歉意。我只是想提供尽可能多的信息以避免混淆。
编辑 1:即使@Jukka 在下面的答案之一中提到,逻辑方法是使用“代码 #1”,但我刚刚检查了 Safari,与 Safari 相比,粗体字体在 Safari 上显得过于粗体到其他浏览器,但是如果我使用“代码 #2”,所有浏览器都呈现相同的内容,所以当使用不同的字体声明时,看起来确实在幕后发生了一些事情。所以此刻我似乎“代码#2”是要走的路,怎么说呢!
【问题讨论】:
-
这些都有效吗?
-
我用过 chrome 和 firefox 和 ie8,它们三个都在工作,这就是为什么我不知道该用哪一个!
-
@font-face{ font-family:Mysegoi; src: url('../fonts/segoeui.eot'); src: url('../fonts/segoeui.eot?#iefix') 格式('embedded-opentype'), url('../fonts/segoeui.woff') 格式('woff'), url(' ../fonts/segoeui.ttf') 格式('truetype'), url('../fonts/helveticaneue-medium-webfont.svg#HelveticaNeue65Medium') 格式('svg'); }
-
你可以使用任何一种,这是我以前做的最好的一种方法
-
如果要使用粗体,请下载特定的粗体并添加