Old 06-13-2007   #1 (permalink)
Be Unique. Be Heard.
 
Jacorre's Avatar
 
Join Date: Jul 2006
Location: USA
Posts: 469

Thumbs down CSS Background Rollover

Looking to add a little style to your image links? Let's use CSS to add a background color that appears when the mouse hovers over the image. This style can be used on a variety of images but we'll be looking at adding this style to affiliate buttons.

STEP ONE

First, we have the html for the actual affiliate button to show up:

Code:
<div class="affiliate">
<a href="http://www.jacorre.com"><img src="http://forums.biorust.com/images/jacorre.gif" width="88" height="31" alt="Jacorre Design Studio" /></a>
</div>
Basically, we wrap the linked image in a div and define a class of affiliate. Make note that the width of the image is 88 pixels and the height is 31 pixels.

STEP TWO

Since we'll probably want to use this style multiple times on a page, that's why I created it as a class. Here's the CSS:

Code:
.affiliate img {
padding: 5px;
border: 0;
}

.affiliate {
float: left;
width: 98px;
height: 41px;
margin-top: 0;
margin-right: 10px;
margin-bottom: 10px;
margin-left: 0;
display: block;
}

.affiliate a:hover {
background-color: #CCCCCC;
display: block;
}
We add 5 pixels of padding around the image. That means the width will now be 88 plus 5 on both the left and right which equals 98 pixels. The height will be 31 plus 5 on both the top and bottom which equals 41 pixels. Making the border equal to zero removes the blue border around a linked image.

We float each div left so they line up next to each other. However, we don't want them too close. So we add 10 pixels of margin to the right and bottom to push them away a bit.

Lastly, we add a background color to the hover.

There's an example at the bottom of my tutorial at CSS Tutorials - Background Rollover
__________________

Jacorre Studios Blog
Jacorre 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
Remove the background paulopires Adobe Photoshop 14 12-12-2006 10:21 AM
See Through Background // Transparent.. ecntrc HTML / PHP / ASP / JS 9 10-13-2006 06:13 AM
I need help on HTMl background. ParaSnake HTML / PHP / ASP / JS 9 12-21-2005 12:30 AM
diagonal line background.. ecntrc Adobe Photoshop 2 11-28-2005 03:34 PM
Forum Background Design Competition Man1c M0g Showrooms & Works In Progress 19 06-30-2004 09:58 PM


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

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