对于简单的线性渐变,请参阅:http ://compass-style.org/reference/compass/css3/images/#mixin-filter-gradient ,另请参阅:CSS(可能与 Compass):跨浏览器渐变
因此,您可以使用如下所示的 SCSS 代码:
@import "compass";
.testgradient {
background: #333; /* Old browsers */
@include background(
linear-gradient(top left, #333, #0c0)
);
@include filter-gradient(#333, #0c0, top left); /* IE 6 - 8 */
}
上面的代码编译成 CSS 如下:
.testgradient {
background: #333;
/* Old browsers */
background: url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4gPHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGRlZnM+PGxpbmVhckdyYWRpZW50IGlkPSJncmFkIiBncmFkaWVudFVuaXRzPSJvYmplY3RCb3VuZGluZ0JveCIgeDE9IjAuMCIgeTE9IjAuMCIgeDI9IjEuMCIgeTI9IjEuMCI+PHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iIzMzMzMzMyIvPjxzdG9wIG9mZnNldD0iMTAwJSIgc3RvcC1jb2xvcj0iIzAwY2MwMCIvPjwvbGluZWFyR3JhZGllbnQ+PC9kZWZzPjxyZWN0IHg9IjAiIHk9IjAiIHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIGZpbGw9InVybCgjZ3JhZCkiIC8+PC9zdmc+IA==');
background: -webkit-gradient(linear, 0% 0%, 100% 100%, color-stop(0%, #333333), color-stop(100%, #00cc00));
background: -moz-linear-gradient(top left, #333333, #00cc00);
background: -webkit-linear-gradient(top left, #333333, #00cc00);
background: linear-gradient(to bottom right, #333333, #00cc00);
*zoom: 1;
filter: progid:DXImageTransform.Microsoft.gradient(gradientType=1, startColorstr='#FF333333', endColorstr='#FF00CC00');
/* IE 6 - 8 */ }