English 中文(简体)
SASS 简化与前缀的混合
原标题:SASS simplify a mixin with prefixes
  • 时间:2012-05-25 10:26:40
  •  标签:
  • sass

有没有更干净的方法来做这个?

@each $prefix in webkit moz ms o {

    -#{$prefix}-transition: all 1s linear;
}
transition: all 1s linear;

我讨厌冗余,我更希望我能做得更简单

<强度 > EDIT :

仅澄清一点。 我不是在寻找一个执行过渡的方法, 我想要的是一个简单化的代码。 在我给您举的例子中, 我可以看到我写了2倍的销售产权。 我想优化它。 这里的示例是我要寻找的东西( 但 < 坚固 > 这是无效的 SCSS < / 坚固 > ) 。

@each $prefix in "-webkit-", "-moz-", "-ms-", "-o-", "" {

    #{$prefix}transition: all 1s linear;
}
最佳回答

过渡不是唯一需要前缀的属性。 随着供应商添加支持, 您可以停止包含前缀 。 如果您抽象了组合中的每一个部分, 您的代码将长期更可维持 。

$default-prefixes: webkit moz ms o;

@mixin build-prefix-values($property, $value, $prefixes: $default-prefixes) {
    @each $prefix in $prefixes {
        -#{$prefix}-#{$property}: #{$value};
    }
    #{$property}: #{$value};
} 

@mixin transition($property: all, $delay: 1s, $timing: linear) {
    $value: $property $delay $timing;
    // use default prefixes
    @include build-prefix-values( transition , $value);
}

// using defaults of  all   1s  and  linear 
p {
    @include transition();
}

// using custom values
.fast {
    @include transition( height ,  .1s ,  ease ,  0 );
}

现在让我们来表示您想要为 边界- radius 写入一个@ mixin, 在那里, webkit 是您唯一需要的前缀 。

@mixin border-radius($radius) {
    $prefixes: webkit;
    @include build-prefix-values( border-radius , $radius, $prefixes);
}
问题回答




相关问题
拆除月度边界(实际大型日历)

采用大型反应日历的Im, 并想要清除包罗日历的边界。 以及如何改变日记栏和日记的颜色? 如何使其发挥作用?

Blueprint, Sass and BrowserCMS

I like quite much browserCMS. And I also favour sass and blueprint. I would like to make these things to play together. Although I read somewhere brosercms can sass and blueprint, it is not obvious ...

Compass blueprint mixins undefined

I am trying to get compass/sass/haml working using blueprint but not having any luck with the blueprint mixins +column(24) just results in Sass syntax error undefined mixin column I m sure I am ...

How can I override blueprint s styles?

Hi I m using blueprint and for some reason I can t override some of their built-in styling (screen.css). So far I ve tried: #asset-index-desc .container div li :border ...

possible to define an array in Sass?

wondering if it is possible to use an array with Sass as I find my self repeating the following sort of thing: .donkey h2 background-color= !donkey .giraffe h2 background-color= !giraffe ...

How do I enable SASS line numbers in CSS output?

How can I enable line numbers in CSS output if I am using SASS? I found an article but I didn t quite understand where to make the modifications http://pivotallabs.com/users/damon/blog/articles/765-...