CSS @font-face仅加载2个字体重量
我正在尝试使用以下CSS,该CSS添加了一个字体系列,具有六个不同的字体重量。
@font-face { font-family: myFont; font-weight: Thin; src: url('../fonts/myFont-Thin.ttf'); }
@font-face { font-family: myFont; font-weight: Light; src: url('../fonts/myFont-Light.ttf'); }
@font-face { font-family: myFont; font-weight: Medium; src: url('../fonts/myFont-Medium.ttf'); }
@font-face { font-family: myFont; font-weight: Regular; src: url('../fonts/myFont-Regular.ttf'); }
@font-face { font-family: myFont; font-weight: Bold; src: url('../fonts/myFont-Bold.ttf'); }
@font-face { font-family: myFont; font-weight: Black; src: url('../fonts/myFont-Black.ttf'); }
.myClass{
font-family: myFont, sans-serif;
font-weight: Medium;
}
当我尝试使用类myClass
时,它使用MyFont-bold.ttf,字体重量为400,而不是使用MyFont-Medium.ttf,字体重量为400。开发人员工具,我能够看到它仅加载了我字体的两个字体重量:大胆和黑色。当我删除黑色字体重量的线路时,它会加载常规和粗体。为什么它仅加载两个字体重量而不是全部。
I'm trying to use the following CSS that adds a font family with six different font-weights.
@font-face { font-family: myFont; font-weight: Thin; src: url('../fonts/myFont-Thin.ttf'); }
@font-face { font-family: myFont; font-weight: Light; src: url('../fonts/myFont-Light.ttf'); }
@font-face { font-family: myFont; font-weight: Medium; src: url('../fonts/myFont-Medium.ttf'); }
@font-face { font-family: myFont; font-weight: Regular; src: url('../fonts/myFont-Regular.ttf'); }
@font-face { font-family: myFont; font-weight: Bold; src: url('../fonts/myFont-Bold.ttf'); }
@font-face { font-family: myFont; font-weight: Black; src: url('../fonts/myFont-Black.ttf'); }
.myClass{
font-family: myFont, sans-serif;
font-weight: Medium;
}
When I try to use the class myClass
, it uses the myFont-Bold.ttf with a font-weight of 400 instead of using the myFont-Medium.ttf with a font-weight of 400. Inside of the developer tools, I'm able to see it's only loaded two font-weights of my font: Bold and Black. When I delete the line for the black font-weight, it then loads in Regular and Bold. Why is it only loading two font-weights instead of all of them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在使用无效的
字体重量
关键字。 (请参阅MDN: font-weight'> font-weight )样式名称例如“灯”或“媒体”通常在桌面环境中使用(例如使用图形应用程序) - 这些样式名称实际上存储在字体文件中(至少以TrueType/ttf等格式)。
但是,浏览器不能使用这些内部存储的样式名称,需要明确的样式/重量映射:
我强烈建议使用数字字体重量值更好地兼容并指定 格式喜欢
格式('trueType')
您还应包括
字体式
以映射正常和斜体样式。You're using invalid
font-weight
keywords. (See MDN: font-weight)Style names like "light" or "medium" are commonly used in desktop environments (e.g using a graphic application) – these style names are actually stored in a font file (at least in formats like truetype/ttf).
However, browsers can't use these internally stored style names and need an explicit style/weight mapping like so:
I strongly recommend using numeric font-weight values for better compatibility as well as specifying the format like
format('truetype')
You should also include a
font-style
to map normal and italic styles.