本文介绍了CSS3白色到透明渐变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用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))到(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;
}

这里转义:


I'm using CSS3 and RGBA to create a white-to-transparent gradient:

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

Fiddle here: http://jsfiddle.net/alecrust/fYz45/

However as you'll notice, the gradient is dark in the middle. I'm getting this:

And I'm expecting this:

How can I rectify?

解决方案

Change your final step to #FFFFFF00 (rgba(255, 255, 255, 0)) instead of #00000000:

http://jsfiddle.net/fYz45/6/

这篇关于CSS3白色到透明渐变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 14:09