Css multiple gradient

偶尔善良 提交于 2019-12-11 20:24:12

问题


I want to style background of one element in CSS, something like this:

  • color gradient from top to bottom with no any transparency,
  • transparency gradient with single color from left to right: left and right with no transparency, and middle with 100% transparency
  • Second gradient should be on higher layer than first. Both placed on 100% of element's area

Code:

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 */;
}

Is this possible to do?


回答1:


It is possible with :after and :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



来源:https://stackoverflow.com/questions/25723110/css-multiple-gradient

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!