Css多重渐变

时间:2014-09-08 11:21:27

标签: css gradient

我想在CSS中设置一个元素的背景样式,如下所示:

  • 从上到下的颜色渐变,没有任何透明度,
  • 从左到右单色的透明度渐变:左边和右边没有透明度,中间是100%透明度
  • 第二个渐变应该在比第一个更高的层上。两者都放置在100%的元素区域

代码:

div.panel div.panel-heading
{
    background: linear-gradient(to bottom, #e8e8e8 0%,#dbdbdb 50%,#cdcdcd 51%,#e0e0e0 100%),
    /* Here I want have got second gradient, with transparency, on higher layer */;
}

这可能吗?

1 个答案:

答案 0 :(得分:2)

可以使用:after:before

.gradient{
    height:400px;
    background: #61fc32;
    background: -moz-linear-gradient(left, #61fc32 0%, #f43034 100%);
    background: -webkit-gradient(linear, left top, right top, color-stop(0%,#61fc32), color-stop(100%,#f43034));
    background: -webkit-linear-gradient(left, #61fc32 0%,#f43034 100%);
    background: -o-linear-gradient(left, #61fc32 0%,#f43034 100%);
    background: -ms-linear-gradient(left, #61fc32 0%,#f43034 100%);
    background: linear-gradient(to right, #61fc32 0%,#f43034 100%);
    position:relative;
}
.gradient:after{
    content:'';
    position:absolute;
    top:0;
    left:0;
    width:100%;
    height:100%;
    background: -moz-radial-gradient(center, ellipse cover, rgba(40,51,201,0) 0%, rgba(40,51,201,1) 100%);
    background: -webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(0%,rgba(40,51,201,0)), color-stop(100%,rgba(40,51,201,1)));
    background: -webkit-radial-gradient(center, ellipse cover, rgba(40,51,201,0) 0%,rgba(40,51,201,1) 100%);
    background: -o-radial-gradient(center, ellipse cover, rgba(40,51,201,0) 0%,rgba(40,51,201,1) 100%);
    background: -ms-radial-gradient(center, ellipse cover, rgba(40,51,201,0) 0%,rgba(40,51,201,1) 100%);
    background: radial-gradient(ellipse at center, rgba(40,51,201,0) 0%,rgba(40,51,201,1) 100%);
}

DEMO