Welcome, Guest

Please login or register

TUTORIALS SUBMENU

PHOTOSHOP    FLASH    ILLUSTRATOR    BLENDER    CINEMA 4D    WEB-CODING    [SUBMIT]

Related Links

Improved CSS Hover Images


NOTE:  This tutorial assumes a basic familiarity with CSS.   If you have no idea how CSS
is laid out or formulated, you may want to read our Introduction to CSS before proceeding.

You see a lot of hover effects on web nowadays. When you hover your mouse cursor over a link it usually changes to something else - It doesn't matter if the link is an image or just text, there's usually some sort of hover effect in place.   If it's a graphical link the hover effect is usually another image displaying the hover effect. This image is often preloaded on page load so that the user sees the effect right away, but there's also another way to do it. How about using just one image and changing its state/position it with CSS?  This is pretty simple trick that I learned from the web some time ago. I haven't seen many tutorials about this, so I decided to share it with you!

Before you can proceed, of course, you need a graphical button designed in the usual way. If you don't have your own you can use the one I'm using (Adobe Photoshop .PSD file), or you can skip the image creation process altogether and use my tutorial button instead.

My button is pretty simple, having one layer for the basic button graphics and another for the hover effect. Now it's time to do some Photoshop magic. To make the effect work you need to create a new image which has both states side-by-side. To do this, simply double your canvas width and copy the images into the one document so that they are side-by-side.  To be perfectly honest it really doesn't matter if the images are adjacent vertically or horizontally... but for the rest of this tutorial we will assume the horizontal method.  If you need a visual example of what you are trying to achieve, take a look at my pre-done tutorial button - its fairly self explanatory!

Once you have finished the image creation and saved it, its time to create the HTML and CSS. You won't need to use the IMG tag at all - Just the A tag.



HTML

<a id="my_button" href="#">my tutorial button</a>



CSS
<style type="text/css" media="all">

a#my_button:link, a#my_button:active, a#my_button:visited {
display: block;
width: 200px;
height: 50px;
background-image: url('csshover_buttons.jpg');
background-repeat: no-repeat;
text-indent: -9999px;
}

a#my_button:hover {
background-position: -200px;
}

</style>

And that's it! Basically what you are doing in this code is creating an A tag set as wide and high as the button, and then using the background-image property to assign the graphics to the tag. You then make a hover CSS tag and move the background image with background-position property to reveal the other image on the right side of your hover image. A bit like a flip-book really!  In this case we move the background image 200px to the left (-200px).

You can see the CSS hover effect in action below:

And that's it!  This method can also be amended to include different link states, but I'll leave that for you to figure out on your own!  ;)   If you have questions about this tutorial you can find me by the nickname Telos on the BioRUST Forums!   Have fun!

- Tutorial written by Telos

Automatic Translations: Translate Into French Translate Into German Translate Into Italian Translate Into Spanish Translate Into Portuguese

Last 5 User Comments


There are no comments for this tutorial yet.
You can place a comment by clicking here.
Amazing Font Pack!

Featured Tutorialsmore

Framing Your Paint...
Framing Your Paint...
- Maxon Cinema 4D -
Whispy Smoke
Whispy Smoke
- Adobe Photoshop -
Animated Movie-Cli...
Animated Movie-Cli...
- Adobe Photoshop -
StarBurst Effects
StarBurst Effects
- Adobe Photoshop -
Membership

Username:
Password:  
Remember Me

Lost Password? || Register

Related Links



Special Options
Printer Friendly Version
Forum Threads

 Deactivate Account
Author: jerinian
Posted: Oct 02nd, 11:16am
Activity: 1 replies, 887 views
 changes....
Author: supertackyman
Posted: Sep 12th, 2:56am
Activity: 2 replies, 1052 views
Back again and with free webhosting :)
Author: ngz
Posted: Aug 14th, 3:50pm
Activity: 0 replies, 1054 views
Cartoon Crab 6 Legs Walk Run created in Blender
Author: patricia3d
Posted: Jun 19th, 12:58pm
Activity: 0 replies, 1935 views
HTML Form Post Array to PHP
Author: Space Cowboy
Posted: May 25th, 2:18pm
Activity: 0 replies, 1832 views
My blog where i create Digi Scrapbook
Author: claudya07
Posted: May 11th, 2:33pm
Activity: 0 replies, 14441 views
Blood Dripping from Letters
Author: patricia3d
Posted: Apr 05th, 3:37am
Activity: 0 replies, 2751 views
A New Designer has joined the ranks
Author: skates1
Posted: Mar 28th, 2:19pm
Activity: 2 replies, 2772 views
The hole in Photoshop
Author: Mars
Posted: Feb 13th, 9:28pm
Activity: 2 replies, 3439 views
Colour Swatch
Author: ebz7350
Posted: Jan 15th, 11:18am
Activity: 0 replies, 2356 views
 BioRUST Forums - Reply to Topic
Author: inonShozy
Posted: Jan 11th, 11:32am
Activity: 8 replies, 2499 views
 Version 2 of my portfolio site.
Author: andrewnleon
Posted: Jan 08th, 6:18am
Activity: 6 replies, 2798 views
Forum Threads

--- Site Resources ---
Total Tutorials:212
Total Downloads:    441
Total Fonts:    4673