Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

is it possible to do this using css - bg image swap

Status
Not open for further replies.

benluke4

Technical User
Jan 27, 2005
127
GB
I have this div

Code:
#login {
	background-image: url(../images_new/login.gif);
	background-repeat: no-repeat;
	background-position: right top;
	height: 31px;
	width: 127px;
	float: right;
	text-align: right;
	margin-top: 0px;
	margin-right: 0px;

}

Is it possible to make the bg image change on mousover??

The reason the image is set as a background is because i have wring over it - in the div

[code
<div id="login">
<p class="login">W&P Assessor Login</p>
</div>
[/code]

If its not possible no worries - just a thought i had?

Thanks again

Ben
 
In cool browsers (like FF, Mozilla, Opera, Safari), you could do it with CSS. To accomodate for silly IE, you might be able to do it like this:
Code:
<style type="text/css">
#login {
    background-image: url(../images_new/login.gif);
    background-repeat: no-repeat;
    background-position: right top;
    height: 31px;
    width: 127px;
    float: right;
    text-align: right;
    margin-top: 0px;
    margin-right: 0px;
    display: block;
    cursor: default;
}

#login:hover {
   background-image: url(../images_new/loginhover.gif);
}
</style>

<a href="#" onclick="return false;" id="login">W&P Assessor Login</a>
This works for me in IE6, Mozilla and Opera7. Just add padding and styling for the font and you're set.
 
Hi Vragabond,

works for me to in IE6 aswell but does this in FF.

When you first rollover it it dissapears then reappears. Then works fine.

And for some reason it messed with the layout and i cant work out how/why?

Cheers Ben
 
The first reappearing/disappearing is probably due to loading the new background. You could avoid that by preloading the picture in javascript or the old css method (have the first image contain both states and rather than changing the image on hover move it so that the other state is visible:

1. make picture twice as high, top is first state, bottom is hovered state
2. on regular link, top of the picture is shown, because it is set as background, the bottom is cropped
3. on hover, push the background image up showing the bottom part and cropping the top.

Messing with layout seems really strange. Are you sure it is not something else messing it up (I have my eye set on the ticker).
 

"have the first image contain both states and rather than changing the image on hover move it so that the other state is visible"

Let me get this clear in my head.
Make the image twice as high by putting the hover state above the link state.

ok get that.

"on hover, push the background image up showing the bottom part and cropping the top."
Dont know how to do this?

Will i still need to preload the image?

Thanks again

Ben

re: layout - looking into it



 
Just to let you know from your suggested tutorial got it working perfectly

Thanks again

BEN
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top