繁体   English   中英

如何为此CSS径向渐变创建Sass mixin?

[英]How to create a Sass mixin for this CSS radial gradient?

我正在使用Ultimate CSS Gradient Generator创建一个径向渐变,它提供了Sass包含的内容,但是在完成background-image mixin遇到了麻烦

CSS

background: rgb(220,156,118);
background: -moz-radial-gradient(center, ellipse cover,  rgba(220,156,118,1) 0%, rgba(220,156,118,1) 49%, rgba(214,101,90,1) 92%, rgba(214,101,90,1) 100%);
background: -webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(0%,rgba(220,156,118,1)), color-stop(49%,rgba(220,156,118,1)), color-stop(92%,rgba(214,101,90,1)), color-stop(100%,rgba(214,101,90,1)));
background: -webkit-radial-gradient(center, ellipse cover,  rgba(220,156,118,1) 0%,rgba(220,156,118,1) 49%,rgba(214,101,90,1) 92%,rgba(214,101,90,1) 100%);
background: -o-radial-gradient(center, ellipse cover,  rgba(220,156,118,1) 0%,rgba(220,156,118,1) 49%,rgba(214,101,90,1) 92%,rgba(214,101,90,1) 100%);
background: -ms-radial-gradient(center, ellipse cover,  rgba(220,156,118,1) 0%,rgba(220,156,118,1) 49%,rgba(214,101,90,1) 92%,rgba(214,101,90,1) 100%);
background: radial-gradient(ellipse at center,  rgba(220,156,118,1) 0%,rgba(220,156,118,1) 49%,rgba(214,101,90,1) 92%,rgba(214,101,90,1) 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#dc9c76', endColorstr='#d6655a',GradientType=1 );

这是Sass mixin @includes

background-color: rgb(220,156,118);
@include filter-gradient(#dc9c76, #d6655a, horizontal);
@include background-image(radial-gradient(center, ellipse cover,  rgba(220,156,118,1)     0%,rgba(220,156,118,1) 49%,rgba(214,101,90,1) 92%,rgba(214,101,90,1) 100%));

我能够为过滤器渐变创建mixin

@mixin filter-gradient($color1, $color2, $direction){
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='$color1', endColorstr='$color2',GradientType=$direction);}

但是由于颜色停止,仍然停留在为径向渐变创建mixin上

@mixin background-image($gradient($position, $type,  $rgba1, $rgba2, $rgba3, $rgba4){
    background: rgb(220,156,118);
    background: -moz-$gradient(center, $type, $rgba1, $rgba2, $rgba3, $rgba4);
    background: -webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(0%,rgba(220,156,118,1)), color-stop(49%,rgba(220,156,118,1)), color-stop(92%,rgba(214,101,90,1)), color-stop(100%,rgba(214,101,90,1)));
    background: -webkit-$gradient(center, $type, $rgba1, $rgba2, $rgba3, $rgba4);
    background: -o-$gradient(center, $type, $rgba1, $rgba2, $rgba3, $rgba4);
    background: -ms-$gradient(center, $type, $rgba1, $rgba2, $rgba3, $rgba4);
    background: $gradient(ellipse at center, $rgba1, $rgba2, $rgba3, $rgba4);
};

你会怎么写这些?

您应该尝试一下Compass,它是一组有用的混合集(如渐变),并应用了跨浏览器行为的最佳实践。

radial-gradient($color-stops, $center-position, $image)

由于webkit的限制,如果使用基于像素的色标,则径向渐变混合效果最好。

Examples:

// Defaults to a centered, 100px radius gradient
+radial-gradient(color-stops(#c00, #00c))

// 100px radius gradient in the top left corner
+radial-gradient(color-stops(#c00, #00c), top left)

// Three colors, ending at 50px and passing thru #fff at 25px
+radial-gradient(color-stops(#c00, #fff, #00c 50px))

// A background image on top of a 100px radius gradient; requires an image
// with an alpha-layer.
+radial-gradient(color_stops(#c00, #fff), top left, image-url("noise.png")))

支持的浏览器:

  • 苹果浏览器
  • Firefox 3.6 Opera

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM