CSS3白色到透明渐变

12

我正在使用CSS3和RGBA创建从白色到透明的渐变:

div {
    background-image: -moz-linear-gradient(left, rgba(255, 255, 255, 1), rgba(0, 0, 0, 0));
    background-image: -ms-linear-gradient(left, rgba(255, 255, 255, 1), rgba(0, 0, 0, 0));
    background-image: -webkit-gradient(linear, 0 0, 100% 0, from(rgba(255, 255, 255, 1)), to(rgba(0, 0, 0, 0)));
    background-image: -webkit-linear-gradient(left, rgba(255, 255, 255, 1), rgba(0, 0, 0, 0));
    background-image: -o-linear-gradient(left, rgba(255, 255, 255, 1), rgba(0, 0, 0, 0));
    background-image: linear-gradient(left, rgba(255, 255, 255, 1), rgba(0, 0, 0, 0));
    background-repeat: repeat-x;
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='rgba(255, 255, 255, 1)', endColorstr='rgba(0, 0, 0, 0)', GradientType=1);
    padding: 2rem 0;
}

在这里尝试:http://jsfiddle.net/alecrust/fYz45/

然而,如您所见,渐变在中间是黑暗的。我得到的是这个:

Getting

而我期望的是这个:

Expecting

我该如何纠正?

4个回答

15

3
最终的颜色应该是白色、透明的,而不是黑色透明的。

而不是

rgba(0, 0, 0, 0)

结束于
rgba (255, 255, 255, 0)

1

If anyone else if having trouble with gradients or getting a certain aspect (angles, transparency, etc.) I recommend trying this tool to learn more: http://www.colorzilla.com/gradient-editor/ The code below is a sample of what it can do. Transparency is controlled by the top squares, color on the lowers. It allows you to keep dropping more colors in. It has good backwards comparability as well and also some has presets.

`div {
background: -moz-linear-gradient(left,  rgba(255,255,255,1) 0%,rgba(255,255,58,0) 100%); /* FF3.6-15 */
background: -webkit-linear-gradient(left,  rgba(255,255,255,1) 0%,rgba(255,255,58,0) 100%); /* Chrome10-25,Safari5.1-6 */
background: linear-gradient(to right,  rgba(255,255,255,1) 0%,rgba(255,255,58,0) 100%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffff', endColorstr='#00ffff3a',GradientType=1 ); /* IE6-9 */
background-repeat: repeat-x;
padding: 2rem 0;
}`


0
div{
     background-color:#ffffff;
     filter:progid:DXImageTransform.Microsoft.gradient(GradientType=1,startColorstr=#ffffff,       endColorstr=#ffff01);
     background-image:-moz-linear-gradient(left top, #ffffff 0%, #ffff01 100%);
     background-image:-webkit-linear-gradient(left top, #ffffff 0%, #ffff01 100%);
     background-image:-ms-linear-gradient(left top, #ffffff 0%, #ffff01 100%);
     background-image:linear-gradient(left top, #ffffff 0%, #ffff01 100%);
     background-image:-o-linear-gradient(left top, #ffffff 0%, #ffff01 100%);
     background-image:-webkit-gradient(linear, left top, right bottom, color-stop(0%,#ffffff),        color-stop(100%,#ffff01));
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接