html - 什么是现代的@font-face 声明?
问题描述
多年来,我使用了以下字体声明:
@font-face {
font-family: 'museo_sans_rounded';
font-style: normal;
font-weight: 500;
src: url('../fonts/museo/museosansrounded-300-webfont.eot');
src: url('../fonts/museo/museosansrounded-300-webfont.eot?#iefix') format('embedded-opentype'),
url('../fonts/museo/museosansrounded-300-webfont.woff2') format('woff2'),
url('../fonts/museo/museosansrounded-300-webfont.woff') format('woff'),
url('../fonts/museo/museosansrounded-300-webfont.ttf') format('truetype'),
url('../fonts/museo/museosansrounded-300-webfont.svg#museo_sans_rounded300') format('svg');
}
现在我只需要支持 IE11 和所有现代浏览器。这个声明可以简化吗?
解决方案
根据这篇关于使用嵌入自定义字体的文章@font-face
:
@font-face 规则允许在网页上加载自定义字体。添加到样式表后,该规则会指示浏览器从其托管位置下载字体,然后按照 CSS 中的指定显示它。
不同的字体有不同级别的浏览器支持。趋势似乎是您可以提供 WOFF 和 WOFF2,但这是他们对“尽可能深的浏览器支持”的建议:
@font-face {
font-family: 'MyWebFont';
src: url('webfont.eot'); /* IE9 Compat Modes */
src: url('webfont.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('webfont.woff2') format('woff2'), /* Super Modern Browsers */
url('webfont.woff') format('woff'), /* Pretty Modern Browsers */
url('webfont.ttf') format('truetype'), /* Safari, Android, iOS */
url('webfont.svg#svgFontName') format('svg'); /* Legacy iOS */
}
对于 IE11:
@font-face {
font-family: 'MyWebFont';
src: url('myfont.woff2') format('woff2'),
url('myfont.woff') format('woff'),
url('myfont.ttf') format('truetype');
}
推荐阅读
- phoenix-framework - 带有 Tailwindcss 和 Alpine JS 的模态
- java - 为 java 批处理应用程序设置 SSL/mTLS 证书身份验证
- server - java:在客户端服务器代码中返回过时的输入
- javascript - 角度加载器留下突出显示颜色
- java - 由于以下错误,需要迁移:已添加属性
- python - 如何在 PyCharm 上降级 pynput 版本
- python - 使用 beautifulsoup 从网站抓取数据 - 嵌套
- python - Django REST-Framework 序列化程序数据帧 CSV 文件
- php - 找出执行辅助函数的控制器和方法(从辅助函数本身)
- powerbi - Power BI:在单个矩阵中组合多个度量