Old 06-05-2006   #1 (permalink)
Eternal Being
 
Join Date: Feb 2006
Location: Finland
Posts: 239

Thumbs up CSS hover tutorial

Ever since I read about this nice little CSS trick on the internet I've been using it with hover images. I haven't seen much tutorials of it so I thought to contribute and wrote this.

You can see a lot of hover effects on web nowadays. When you hover your mouse cursor over a link it usually changes to something else. 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 usually preloaded on page load so that the user sees the effect right away but there's also a another way to do it. How about using just one image and change it with CSS? Keep on reading to find out how.

Just do the graphical button the way you have always done. If you don't have your own you can use the one I used in this tutorial (Adobe Photoshop .PSD file). You can also skip the image creation process and use my tutorial button instead.

My button is pretty simple one and it has one layer for the basic button graphics and another for the hover effect. Now it's time to do some photoshop magic. You have to create another image which has these both states in it. Copy the button with the basic state on to another image

* Ctrl + A
* Edit | Copy Merged
* File | New | OK
* Ctrl + V

Now you have the basic image in place. Next step is to make enough room in the image to fit the hover state

* Image | Canvas size ...
* Double the image width. In my case 200 * 2 = 400. Make sure the anchor is on the middle left and relative is unchecked
* Now repeat the first part and copy the button in it's hover state to the image
* Place the hover state layer to the right side of the image so that in the end you have one image with two images side by side
* Save it as .jpg

Now it's time to create the HTML and CSS. You don't use the IMG tag at all on this one. Just the A tag.
HTML
HTML Code:
<a id="my_button" href="#">my tutorial button</a>
CSS
HTML Code:
<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>
That's it. So basicly what you are doing is that you create an A tag and you set it to be as wide and high as the button. Use background-image to set the graphics to it. Then you make a hover css and you move the background image with background-position to reveal the other image on the right side of your hover image. In this case move the background image 200px to the left (-200px).

Wanna see it in action?
__________________

Last edited by Telos; 06-06-2006 at 06:53 AM.
Telos is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 06-05-2006   #2 (permalink)
Sheep Worrier
 
Man1c M0g's Avatar
 
Join Date: Sep 2003
Location: Portsmouth, UK.
Posts: 4,061
Blog Entries: 14

Send a message via ICQ to Man1c M0g Send a message via MSN to Man1c M0g Send a message via Skype™ to Man1c M0g
Nice, cute, and effective! Mind if I pop it onto the Biorust main pages?
__________________
Man1c M0g is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 06-05-2006   #3 (permalink)
Registered User
 
bedlam123's Avatar
 
Join Date: Jul 2005
Location: Somewhere in between
Posts: 797

Thank you Telos, this works great and is not complicated!
bedlam123 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 06-06-2006   #4 (permalink)
Eternal Being
 
Join Date: Feb 2006
Location: Finland
Posts: 239

Yeah Man1c M0g, go ahead. Just use it the way you see best.

You can also see an effective css replacement effect on this tutorial. It's always nicer to have all website images as background images and not use the IMG tag so using background-image, width, height and text-indent (-9999px) you can show all your images as background images. I usually do the basic layout images like that and use IMG tag only in dynamic content since the image replacement tags usually need an unique ID to work and it would be pointless to create css and id's on the fly. So image replacement goes like this:

HTML Code:
<style type="text/css">
    h1#replacement {
        width: 100px;
        height: 100px;
        background-image: url('myimage.jpg');
        background-repeat: no-repeat;
        text-indent: -9999px;
    }
</style>

<h1 id="replacement">My replaced image</h1>
__________________
Telos is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 06-06-2006   #5 (permalink)
...Abstract Artist...
 
misswynne's Avatar
 
Join Date: Mar 2006
Location: Northern B.C
Posts: 13

Wow, that is pretty sweet! You're right about most links having hover effects - I use them almost every day....
__________________
Every cloud has a silver lining.... except those on which I have applied a simple bronze glow!

---------------------

| Virtual Pets | Games
misswynne is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 06-06-2006   #6 (permalink)
Sheep Worrier
 
Man1c M0g's Avatar
 
Join Date: Sep 2003
Location: Portsmouth, UK.
Posts: 4,061
Blog Entries: 14

Send a message via ICQ to Man1c M0g Send a message via MSN to Man1c M0g Send a message via Skype™ to Man1c M0g
Many thanks Telos! I'll add your tutorial onto my list of tutorials to add!
__________________
Man1c M0g is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 06-08-2006   #7 (permalink)
Sheep Worrier
 
Man1c M0g's Avatar
 
Join Date: Sep 2003
Location: Portsmouth, UK.
Posts: 4,061
Blog Entries: 14

Send a message via ICQ to Man1c M0g Send a message via MSN to Man1c M0g Send a message via Skype™ to Man1c M0g
And the tutorial is now online over at http://www.biorust.com/tutorials/detail/227/en/ . I made a few changes, but nothing too drastic. Many thanks for your tutorial m8!
__________________
Man1c M0g is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 06-09-2006   #8 (permalink)
Eternal Being
 
Join Date: Feb 2006
Location: Finland
Posts: 239

Thanks for putting it there. Changes were good ones so thanks for them too. I was about to write another tutorial yesterday but didn't find the time. Going to do it this weekend if my schedule is mercyful enough and yes, it's going to be a PHP tut.
__________________
Telos is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Tutorial Database List - Must see for Tutorial Writters BlueSfear General Discussions 1 02-24-2006 05:43 PM
Super Guest Tutorial Sunday! Man1c M0g Announcements 4 11-02-2005 03:57 AM
Help with Membership Tutorial joemikecox HTML / PHP / ASP / JS 4 02-23-2005 09:39 PM
My blender&yafray HDRI tutorial Milkdrop Blender 3D 14 09-01-2004 06:33 PM
Regarding the 'Planetary Masses' Tutorial Pesketron BioRUST Specific Threads 22 06-16-2004 10:59 AM


All times are GMT +1. The time now is 12:11 AM.
Content Relevant URLs by vBSEO 3.2.0 RC7

Design & Content © BioRUST 2007 :: PRIVACY STATEMENT :: LEGAL INFORMATION :: ADVERTISING MEDIA KIT