Jump to content

CSS img roll over help!


clanstyles

Recommended Posts

Hey, I have

<a href="#"><img class="purchase" src="images/nav_purchase.gif" alt="Purchase" /></a>

.purchase {
width: 142px;
height: 28px;
margin-left: 285px;
position: absolute;
border: 0px;
}

.purchase a:hover { background-image: url(images/nav_purchase_roll.gif); }

 

now I need to roll over that img and have it work fine. It doesn't work... heh (img does exist).

Link to comment
Share on other sites

Your complete code logic is flawed.

 

You can't use css to change markup. You can use stylesheets to "style" markup. In your code, you are trying to use css to change the img src="" tag in your markup. You can't do that.

 

Here is a sample of what you can do:

 

<a href=""></a>

 

a {
display: block;
width: 142px;
height: 28px;
background: url(images/nav_purchase.gif) no-repeat;
}
a:hover {
background: url(images/nav_purchase_roll.gif) no-repeat;
}

Link to comment
Share on other sites

<a href="#"><img class="purchase" src="images/nav_purchase.gif" alt="Purchase" /></a>

.purchase a:link {
width: 142px;
height: 28px;
margin-left: 285px;
        background-image: url(images/nav_purchase.gif);
        padding: 5px; /*Do whatever padding is necessary to align text */
position: absolute;
border: 0px;
}

.purchase a:visited {
width: 142px;
height: 28px;
margin-left: 285px;
        background-image: url(images/nav_purchase.gif);
        padding: 5px; /*Do whatever padding is necessary to align text */
position: absolute;
border: 0px;
}

.purchase a:hover {
width: 142px;
height: 28px;
margin-left: 285px;
        background-image: url(images/nav_purchase_roll.gif);
        padding: 5px; /*Do whatever padding is necessary to align text */
position: absolute;
border: 0px;
}

.purchase a:active {
width: 142px;
height: 28px;
margin-left: 285px;
        background-image: url(images/nav_purchase.gif);
        padding: 5px; /*Do whatever padding is necessary to align text */
position: absolute;
border: 0px;
}

 

Just remember to adjust the height and width of the div depending on the padding.

Link to comment
Share on other sites

<a href="#"><img class="purchase" src="images/nav_purchase.gif" alt="Purchase" /></a>

.purchase a:link {
width: 142px;
height: 28px;
margin-left: 285px;
        background-image: url(images/nav_purchase.gif);
        padding: 5px; /*Do whatever padding is necessary to align text */
position: absolute;
border: 0px;
}

.purchase a:visited {
width: 142px;
height: 28px;
margin-left: 285px;
        background-image: url(images/nav_purchase.gif);
        padding: 5px; /*Do whatever padding is necessary to align text */
position: absolute;
border: 0px;
}

.purchase a:hover {
width: 142px;
height: 28px;
margin-left: 285px;
        background-image: url(images/nav_purchase_roll.gif);
        padding: 5px; /*Do whatever padding is necessary to align text */
position: absolute;
border: 0px;
}

.purchase a:active {
width: 142px;
height: 28px;
margin-left: 285px;
        background-image: url(images/nav_purchase.gif);
        padding: 5px; /*Do whatever padding is necessary to align text */
position: absolute;
border: 0px;
}

 

Just remember to adjust the height and width of the div depending on the padding.

 

This is extremely poorly coded. It uses position: absolute, unless there is a special reason to use it, do not ever use position: absolute; .

 

It is unnecessary to add multiple declarations and specify their individual properties, when you can combine them. You should also never specify "margin-left" but say "margin: 0 0 __px 0;" instead. This is because you are letting the browser affect the margins. You don't want to use the default, you want to use what YOU want.

 

I hope that helps. I still recommend use the code that I posted earlier. It is cleaner and easier to customize.

Link to comment
Share on other sites

should really keep both images togerther, like so

 

buttest.gif

 

style being

 

.but {
height:41px; 
width:113px;
background:url(buttest.gif) left no-repeat;
}
.but:hover {
height:41px; 
width:113px;
background:url(buttest.gif) right no-repeat;
cursor:pointer; /*IE Hack*/
}

 

image container being

 

<a href="#"><div class="but"></div></a>

 

done, its that simple, plus you dont have multiple button images.

Link to comment
Share on other sites

You can make this:

 

.but:hover {

height:41px;

width:113px;

background:url(buttest.gif) right no-repeat;

cursor:pointer; /*IE Hack*/

}

 

shorter by using this:

 

.but:hover {

background-position: top right;

}

 

You don't need to re-declare statements in the hover state if they are the same as in the non-hover state.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.