Old 06-13-2007   #1 (permalink)
Registered User
 
Jacorre's Avatar
 

Join Date: Jul 2006
Location: USA
Posts: 545
Images: 7

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 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
rollover button using adobe? mary HTML / PHP / ASP / JS 9 02-18-2008 05:15 PM
CSS - Rollover image problem with IE Neo824 HTML / PHP / ASP / JS 4 10-27-2007 01:43 AM
rollover problem LimitLess Adobe Photoshop 6 03-11-2007 03:08 AM
Greatest Hits Rollover RedDeath Showrooms & Works In Progress 0 12-02-2005 07:28 AM
ImageReady rollover help please! Lantern Adobe Photoshop 2 04-07-2004 08:44 PM


All times are GMT +1. The time now is 07:42 AM.

Powered by vBulletin Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.3.2

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