淘先锋技术网

首页 1 2 3 4 5 6 7

CSS渐变.gif

今天重写模板的时候需要用到这个效果,线性渐变,属于CSS3 linear-gradient写法!

之前已经写过一篇关于:CSS3 经典教程系列:CSS3 线性渐变(linear-gradient)

案例HTML代码:

<div class="box">
 <div class="bg"></div>
 <div class="img">
  img+p
 </div>
 <div class="cname">
   catename
 </div>
</div>

 CSS:

.box{width: 100%;height: 165px;position: relative;}
.box .bg{position: absolute;left: 0;top: 0;right: 0;bottom: 0; 
 background: -webkit-linear-gradient(top,rgba(0,0,0,0),rgba(0,0,0,.4)); /*Safari、Chrome*/
 background: -moz-linear-gradient(top,rgba(0,0,0,0),rgba(0,0,0,.4)); /*Firefox,Flock*/
 background: -o-linear-gradient(top,rgba(0,0,0,0),rgba(0,0,0,.4)); /*Opera*/
 background: linear-gradient(top,rgba(0,0,0,0),rgba(0,0,0,.4));
}
.box:hover .bg{
 background: -webkit-linear-gradient(top,rgba(0,0,0,0),rgba(0,0,0,.2));
 background: -moz-linear-gradient(top,rgba(0,0,0,0),rgba(0,0,0,.2));
 background: -o-linear-gradient(top,rgba(0,0,0,0),rgba(0,0,0,.2));
 background: linear-gradient(top,rgba(0,0,0,0),rgba(0,0,0,.2));
}