首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >配置compass浏览器支持(Compass 1.x语法)

配置compass浏览器支持(Compass 1.x语法)
EN

Stack Overflow用户
提问于 2014-09-16 07:51:27
回答 1查看 3.4K关注 0票数 5

使用0.12.x版本的Compass,我用这种方式定义了对旧版本的支持:

代码语言:javascript
复制
@import "compass/support"

$legacy-support-for-ie6: false;
$legacy-support-for-ie7: true;
$legacy-support-for-ie8: true;
$legacy-support-for-mozilla: false;

@if ($legacy-support-for-ie7) {
  // specific declaration if ie7 is supported
}

我想知道如何在browser support之后定义Compass 1.x system。也许是这样的:

代码语言:javascript
复制
// Add support for a specific browser
$browser-minimum-versions: (
  'ie': "7",
  'ie': "8"
);

// Reject browsers
$supported-browsers: reject(browser-versions("ie"), "6", "7", "8");

但是它返回该错误(运行在Compass 1.0.1上):

代码语言:javascript
复制
(Line 206 of /Library/Ruby/Gems/2.0.0/gems/compass-core-1.0.1/stylesheets/compass/_support.scss: 5.5 is not known browser.)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-10-07 14:15:08

排除浏览器是通过修改$graceful-usage-threshold变量来完成的。如果Browser X仅占市场份额的4.99%,则需要将其设置为5

代码语言:javascript
复制
$debug-browser-support: true;
$browser-minimum-versions: (
  "ie": "9"
);
$graceful-usage-threshold: 4.46163;

@import "compass";

.foo {
  @include opacity(.5);
  @include border-radius(10px);
}

输出:

代码语言:javascript
复制
.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开始发挥作用的时候。

代码语言:javascript
复制
$browser-minimum-versions: (
  "ie": "9",
  "safari": "4"
);

输出:

代码语言:javascript
复制
.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变量就起作用了:

代码语言:javascript
复制
$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;
  }
}
票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25863370

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档