Latest tutorial: Premium Flash Files | Ask Tutorial5! | Subscribe to RSS Register Login Find Hobbies
Advertisement
Do you need more help? You can now Ask Tutorial5! and get free support - Ask a question now!

CSS Images Menu using transparency for your website

(12 votes)
Written by AnaS   

In this CSS tutorial it wil be explained how to create an awesome CSS menu using images and some transparency level.

Prepare three pictures with 100x75 dimensions. The final result should be a CSS images menu like the one below:

Css images menu Css images transparency Css websitemenu

For creating a transparent image it will be used filter:alpha(opacity=n) for Internet Explorer versions and -moz-opacity:m for Mozilla browsers, where:
 - n represents an integer between 0 and 100;
 - m represents a value between 0.0 and 1.0.
When the value of n or m is lower, the more transparent the image is.

Let's begin!

1. Put  your images on your website and make a link to them like below:

 <a href="http://www.tutorial5.com"> <img src="cssmenu1.jpg" border="0" alt="Css images menu"></a>
 <a href="http://www.rentahobby.com"> <img src="cssmenu2.jpg" border="0" alt="Css images transparency"></a>
<a href=" http://www.tutorial5.com"> <img src="cssmenu3.jpg" border="0" alt="Css website menu"></a>
 
To src property insert the path to your image. For example images/cssmenu/yourimage.jpg.

2. Now we will add some style for setting the images transparency to 50%. Add the following code to every image:

 style="-moz-opacity:0.5;filter:alpha(opacity=50)"

3. Now, we want to change the transparency of the images back to none when the mouse is over them. We will use onmouseover and onmouseout Javascript events. So, if the mouse is over the image we will apply a style with no transparency (that means n=100 and m=1.0), and when the mouse is not we will apply a style with 50% transpanrency (that means n=50 and m=0.5). So, add the next code to each of your images: 
  onmouseover="this.style.MozOpacity=1; this.filters.alpha.opacity=100" 
  onmouseout="this.style.MozOpacity=0.5; this.filters.alpha.opacity=50"

4. And in the end you vode menu should look like below:

<a href="<http://www.tutorial5.com"> <img src="cssmenu1.jpg" border="0" alt="Css images menu" style="-moz-opacity:0.5;filter:alpha(opacity=50)" onmouseover="this.style.MozOpacity=1; this.filters.alpha.opacity=100" onmouseout="this.style.MozOpacity=0.5; this.filters.alpha.opacity=50" ></a>

 <a href="
http://www.rentahobby.com"> <img src="cssmenu2.jpg" border="0" alt="Css images transparency" style="-moz-opacity:0.5;filter:alpha(opacity=50)" onmouseover="this.style.MozOpacity=1; this.filters.alpha.opacity=100" onmouseout="this.style.MozOpacity=0.5; this.filters.alpha.opacity=50" ></a>

 <a href="
http://www.tutorial5.com"> <img src="cssmenu3.jpg" border="0" alt="Css website menu" style="-moz-opacity:0.5;filter:alpha(opacity=50)" onmouseover="this.style.MozOpacity=1; this.filters.alpha.opacity=100" onmouseout="this.style.MozOpacity=0.5; this.filters.alpha.opacity=50" ></a>


Hope this tutorial improved your CSS knowledge!


 



Subscribe now via RSS feed and get all the new tutorials

written by barat , October 12, 2007

Why to use something that isn't realy a CSS, and Isn't cross-browser? It doesn't work on Opera ...
It's better to use CSS rollovers (using background-position trick) ...
written by Lata , December 15, 2007

Yes I want to make a website in css but i dont know how to start. what is the first step can you send me a web page in css with complete details.
written by maran , February 20, 2008

hi,

fine..but that is not Valid XHTML i got a "Parse Error - opacity=50"
written by veronica , April 01, 2008

Just wanted to thank you! I learned how to make my own menu with images...I love how easly explained it was...thanks a bunch!

Do you need more help? Ask now!
 

busy
Last Updated ( Monday, 10 September 2007 )