排除浏览器是通过修改$graceful-usage-threshold
变量来完成的。如果浏览器 X 只有 4.99% 的市场份额,您希望将其设置为5
.
$debug-browser-support: true;
$browser-minimum-versions: (
"ie": "9"
);
$graceful-usage-threshold: 4.46163;
@import "compass";
.foo {
@include opacity(.5);
@include border-radius(10px);
}
输出:
.foo {
/* Content for ie 8 omitted.
Minimum support is 9. */
opacity: 0.5;
/* Capability border-radius is not prefixed with -moz because 0.25036% of users are affected which is less than the threshold of 4.46163. */
/* Capability border-radius is not prefixed with -ms because 0% of users are affected which is less than the threshold of 4.46163. */
/* Capability border-radius is not prefixed with -o because 0% of users are affected which is less than the threshold of 4.46163. */
/* Capability border-radius is not prefixed with -webkit because 0.1583% of users are affected which is less than the threshold of 4.46163. */
border-radius: 10px;
}
请注意,这会导致您可能想要支持的其他少数浏览器被排除在外。这就是$browser-minimum-versions
发挥作用的时候。
$browser-minimum-versions: (
"ie": "9",
"safari": "4"
);
输出:
.foo {
/* Content for ie 8 omitted.
Minimum support is 9. */
opacity: 0.5;
/* Capability border-radius is not prefixed with -moz because 0.25036% of users are affected which is less than the threshold of 4.46163. */
/* Capability border-radius is not prefixed with -ms because 0% of users are affected which is less than the threshold of 4.46163. */
/* Capability border-radius is not prefixed with -o because 0% of users are affected which is less than the threshold of 4.46163. */
/* Capability border-radius is prefixed with -webkit because safari "4" is required. */
/* Creating new -webkit context. */
-webkit-border-radius: 10px;
border-radius: 10px;
}
作品中有一些变化,以便更容易排除旧浏览器。你可以在这里关注他们: https ://github.com/Compass/compass/issues/1762
如果你想为特定的浏览器制定规则,那么$critical-usage-threshold
变量就会发挥作用:
$debug-browser-support: true;
$browser-minimum-versions: (
"ie": "9"
);
$critical-usage-threshold: 4.46163;
$graceful-usage-threshold: 4.46163;
@import "compass";
.foo {
@include for-legacy-browser('ie', '8') {
color: green;
// this is based on $critical-usage-threshold by default
// if $critical-usage-threshold is lower than the version's usage
// then this content will be generated
}
@if support-legacy-browser('ie', '8') {
color: red;
}
}