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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

bg image swap on mousover

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>

I know you can do rollover imagmes but how would i make the bg image change that is inside a div???

Thanks for any advice

Ben
 

Change your DIV to be:

Code:
<div id="login" onmouseover="this.style.backgroundImage='url(../images_new/rolledOver.gif)'" onmouseout="this.style.backgroundImage='url(../images_new/login.gif)'">

You can remove the onmouseout if you do not want the image to change back when the mouse is removed.

Hope this helps,
Dan

 
Hi Billy ray i just tried your code, but its not working.

This is what i have
Code:
<div id="login" onmouseover="this.style.backgroundImage='url(../images_new/loginb.gif)'" onmouseout="this.style.backgroundImage='url(../images_new/login.gif)'">
          <p class="login">W&P Assessor Login</p>
        </div>

Here's the style for the login div
Code:
#login {
	background-image: url(../images_new/login.gif);
	background-repeat: no-repeat;
	background-position: right top;
	height: 31px;
	width: 118px;
	float: right;
	text-align: right;
	margin-top: 0px;
	margin-right: 0px;

}

Thanks again

Ben
 

It worked fine for me in both IE6 and FF1. What browser are you using? Can you post a URL to the page?

Dan

 

It works fine in IE for me, too... But only after a short delay (hold the mouse over the image for a few seconds).

I suggest pre-loading the image to avoid this.

Hope this helps,
Dan

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top