views:

620

answers:

2

How can I implement cross browser opacity gradient (not color gradient)? See following code:

<div style="background-color:Red;display:block;height:500px;width:500px;filter:alpha(Opacity=100, FinishOpacity=0, Style=1, StartX=0, StartY=0, FinishX=0, FinishY=500)"></div>

It works fine in IE but not in other browsers like firefox,safari..etc. What is equivalent syntax for firefox? Please don't suggest me to use gradient image.

+5  A: 

There's -moz-linear-gradient for recent Firefox versions and -webkit-gradient for WebKit browsers. Transparency for those two should be possible by using rgba colors.

https://developer.mozilla.org/en/CSS/-moz-linear-gradient
http://developer.apple.com/safari/library/documentation/...

The only real 100% cross-browser compatible solution is an image though.

deceze
+2  A: 

Thanks @deceze,

I am writing sample css for other people having same requirement

top:0px;
    opacity: 0.6;       
    width: 1944px; 
    height: 896px; 
    position: absolute; 
    z-index: 500;
background-color:#dcdcdc;
        /* For WebKit (Safari, Google Chrome etc) */
        background: -webkit-gradient(linear, left top, left bottom, from(#dcdcdc), to(rgba(215,212,207,0)));
        /* For Mozilla/Gecko (Firefox etc) */
        background: -moz-linear-gradient(top, #dcdcdc, rgba(215,212,207,0));
        /* For Internet Explorer 5.5 - 7 */
        filter:alpha(Opacity=70, FinishOpacity=0, Style=1, StartX=1242, StartY=0, FinishX=1242, FinishY=696);
        /* For Internet Explorer 8 */
        -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=70, FinishOpacity=0, Style=1, StartX=1242, StartY=0, FinishX=1242, FinishY=696)";
Brij