Transparent images using css

» 28 April 2009 » In Css Articles »

It is very easy to make an image transparent, by using opacity, using only 1 line in your css. In this example, I’ll set the opacity to 40%. This is the html code:

?View Code HTML4STRICT
<img src="#" width="150" height="150" alt="image" class="transparent" />

You can see that we call for the class “transparent”, in the css class transparent, we have the following code:

.transparent{ opacity:0.4;filter:alpha(opacity=40) }

This is all that it takes to show a tranparent image in css. You can also use the same code for transparency on text. Note that Firefox uses the property opacity:value for transparency, IE uses filter:alpha(opacity=value). This works in all modern browsers.
Here you can see a screenshot, one with the opacity set, and one without the opacity:
transparencytest
In CSS3, the syntax for transparency/opacity will be “opacity:value”.

Tags: , , , , , ,

Trackback URL

No Comments on "Transparent images using css"

You must be logged in to post a comment.