不幸的是,我无法在线找到一个解释使用语法的最佳方式的源代码 – 在我看来,字体功能设置是前缀地狱的另一个例子.
目前我写的是这样的,但我不知道是否覆盖了所有支持这些功能的浏览器.
.element { -webkit-font-feature-settings: "kern" 1,"liga" 1,"case" 1; -moz-font-feature-settings: "kern=1","liga=1","case=1"; -moz-font-feature-settings: "kern" on,"liga" on,"case" on; -ms-font-feature-settings: "kern" 1,"case"; -o-font-feature-settings: "kern","liga","case"; font-feature-settings: "kern","case"; }
更具体地说,-moz语法似乎很奇怪.一些来源声称这是要使用的语法:
-moz-font-feature-settings: "liga=1"; /* Firefox 14 and before */ -moz-font-feature-settings: "liga" on; /* Firefox 15 */
其他人就这样做:
-moz-font-feature-settings: "cswh=1"; -moz-font-feature-settings: "cswh";
-webkit也一样;有些写的就像这样:
-webkit-font-feature-settings: "liga" on,"dlig" on;
而其他人则这样做:
-webkit-font-feature-settings: "liga","dlig";
或者像这样:
-webkit-font-feature-settings: "liga" 1,"dlig" 1;
而且,还有文本渲染:optimizelegibility;这似乎与“kern”和“liga”相同,至少在webkit浏览器中.
解决方法
If present,a value indicates an index used for glyph selection. An value must be 0 or greater. A value of 0 indicates that the feature is disabled. For boolean features,a value of 1 enables the feature. For non-boolean features,a value of 1 or greater enables the feature and indicates the feature selection index. A value of ‘on’ is synonymous with 1 and ‘off’ is synonymous with 0. If the value is omitted,a value of 1 is assumed.
这意味着“liga”1,“liga”和liga都做同样的事情.
正如BoltClock在他对这个问题的评论中提到的,“feature = value”不是有效的语法,似乎是Firefox特有的东西.
Opera和IE(< 10)do not support font-feature-settings
at all,所以-o- *和-ms- *属性大概是没用的.
总的来说,所有当前支持的浏览器的工作语法似乎是:
.element { -webkit-font-feature-settings: "kern","case"; /* No variation */ -moz-font-feature-settings: "kern=1","case=1"; /* Firefox 4.0 to 14.0 */ -moz-font-feature-settings: "kern","case"; /* Firefox 15.0 onwards */ -moz-font-feature-settings: "kern" 1,"case" 1; /* Firefox 15.0 onwards explicitly set feature values */ font-feature-settings: "kern","case"; /* No variation */ }