So what we will do here. We have two images that are a like, only difference is color of icon.


We want to have first image (link.jpg) to be shown will idle, but when we go with mouse over the link we want to have second image to be shown (over.jpg). Images are 16*16px.
Ok let's start with CSS. First we will format body.
CODE
body{
margin:0;
padding:20px;
text-align:justify;
background:#FFFFFF;
}
No fuss here. Margin set to 0, padding to 20px so that we have better representation of our link. Background of body is set to background of "link" and "over" jpegs, which is white (#FFFFFF).
Ok, let take a look at next image, where will be shown our result of this tutorial and explanation of padding in p.class »Link«.

We see that p.class »Link« has left padding set to 20px, so that text is moved 20px more to the right side that it won't interact with hover effect images (link and over jpegs).
Code for this action is next:
CODE
p.link{
font: 12px/16px verdana, arial;
color: #797983;
margin:0px;
padding:0px 0px 0px 20px;
text-align:justify;}
font: 12px/16px verdana, arial;
color: #797983;
margin:0px;
padding:0px 0px 0px 20px;
text-align:justify;}
Font size set to 12px and spacing to 16px, which is same height as our hover effect images, padding-left set to 20px, so width of hover effect images is also 16px which leaves us with 4px of space infront of hyperlink text. Text is justified.
Next code will define idle state of hyperlink:
CODE
p.link a{
padding:0 0 0 20px;
color: #797983;
text-decoration:underline;
background:url(link.jpg) center left no-repeat;
}
padding:0 0 0 20px;
color: #797983;
text-decoration:underline;
background:url(link.jpg) center left no-repeat;
}
We have defined padding of hyperlink, text decoration, which can be none (no underline) or underline (underlined). We have also defined background image for hyperlink, which is link.jpg (idle state). Image is aligned to left and centered.
Next code will define hover effect:
CODE
p.link a:hover{
color: #797983;
text-decoration:underline;
background:url(over.jpg) center left no-repeat;
}
color: #797983;
text-decoration:underline;
background:url(over.jpg) center left no-repeat;
}
In this section we have defined hover effect, everything stays same only thing that will change is changing from link.jpg to over.jpg when going over the hyperlink with a mouse (hover).
So whole CSS file should look like this:
CODE
body{
margin:0;
padding:20px;
text-align:justify;
background:#FFFFFF;
}
p.link{
font: 12px/16px verdana, arial;
color: #797983;
margin:0px;
padding:0px 0px 0px 20px;
text-align:justify;}
p.link a{
padding:0 0 0 20px;
color: #797983;
text-decoration:underline;
background:url(link.jpg) center left no-repeat;
}
p.link a:hover{
color: #797983;
text-decoration:underline;
background:url(over.jpg) center left no-repeat;
}
margin:0;
padding:20px;
text-align:justify;
background:#FFFFFF;
}
p.link{
font: 12px/16px verdana, arial;
color: #797983;
margin:0px;
padding:0px 0px 0px 20px;
text-align:justify;}
p.link a{
padding:0 0 0 20px;
color: #797983;
text-decoration:underline;
background:url(link.jpg) center left no-repeat;
}
p.link a:hover{
color: #797983;
text-decoration:underline;
background:url(over.jpg) center left no-repeat;
}
Not a big one for such a nice hover effect
Next thing we will do is HTML file which will be linked to layout1.css file. You can change the name of this file to personal needs, but remember that you must also change link in HTML file which is:
CODE
<style type="text/css" media="all">@import "layout1.css";</style>
So this is HTML file:
CODE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Hover effects</title>
<meta http-equiv="content-type" content="text/html;charset=windows-1250"/>
<style type="text/css" media="all">@import "layout1.css";</style>
</head>
<body>
<p class="link"><a href="#" title="">Hyperlink</a></p>
</body>
</html>
<html>
<head>
<title>Hover effects</title>
<meta http-equiv="content-type" content="text/html;charset=windows-1250"/>
<style type="text/css" media="all">@import "layout1.css";</style>
</head>
<body>
<p class="link"><a href="#" title="">Hyperlink</a></p>
</body>
</html>
Let me explain this code:
CODE
<p class="link"><a href="#" title="">Hyperlink</a></p>
In CSS file we have defined p.link class.
CODE
<p class="link">
defines p.link class,CODE
href="#"
link to some other file and CODE
Hyperlink
text that will be displayed in browser.Working example is located here.
CSS file is located here.
Critics, suggestions or anything else is welcome as always.
Robert

