为了添加透明度,我们使用 rgba() 函数来定义颜色结点。rgba() 函数中的最后一个参数可以是从 0 到 1 的值,它定义了颜色的透明度:0 表示完全透明,1 表示完全不透明。rgba()后面的百分比表示位置。
具体代码:
<span style="color: #800000;">background: -webkit-linear-gradient(top, rgba(255,255,255,0.4)0%, rgba(255,255,255,0.2)75%, rgba(255,255,255,0)98%);</span><span style="color: #008000;">/*</span><span style="color: #008000;"> Safari、Chrome </span><span style="color: #008000;">*/</span><span style="color: #800000;"> background: -o-linear-gradient(bottom, rgba(255,255,255,0.4)0%, rgba(255,255,255,0.2)75%, rgba(255,255,255,0)98%);</span><span style="color: #008000;">/*</span><span style="color: #008000;"> Opera </span><span style="color: #008000;">*/</span><span style="color: #800000;"> background: -moz-linear-gradient(bottom, rgba(255,255,255,0.4)0%, rgba(255,255,255,0.2)75%, rgba(255,255,255,0)98%);</span><span style="color: #008000;">/*</span><span style="color: #008000;"> Firefox </span><span style="color: #008000;">*/</span><span style="color: #800000;"> background: linear-gradient(to bottom, rgba(255,255,255,0.4)0%, rgba(255,255,255,0.2)75%, rgba(255,255,255,0)98%); </span><span style="color: #008000;">/*</span><span style="color: #008000;"> 标准的语法(必须放在最后) </span><span style="color: #008000;">*/</span>
注意:Internet Explorer 9 及之前的版本不支持渐变。