PDA

View Full Version : CSS Hover Change Background...


Winterworks
02-23-2009, 10:33 PM
A part of my .css file is this...

.navigation_text {
margin-left: 43px;
width:155px;
height:48px;
text-decoration: none;
font-size: 12px;
color: #000000;
background: #F8F8FF no-repeat top left;

}

Here's the code to match it in my index.html...

<div class="navigation_text"><strong>Website Homepage:</strong><br />Click <a href="http://www.website.com/index.html">here</a> to view our<br />homepage.</div>

Right now, on the site, the <div> box has a background color of #F8F8FF, which is exactly what I want. But I want it so when you put your mouse over it, the background of the whole box changes. I want it to change to white.

Not the links, or text, but background...

Yes, I'm just learning CSS. :p

TigerC10
02-23-2009, 10:45 PM
<style type="text/css">
.navigation_text {
margin-left: 43px;
width:155px;
height:48px;
text-decoration: none;
font-size: 12px;
color: #000000;
background: #F8F8FF;
}
.navigation_text_hover {
margin-left: 43px;
width:155px;
height:48px;
text-decoration: none;
font-size: 12px;
color: #000000;
background: #FFFFFF;
}
</style>

<div class="navigation_text" onmouseover="this.className = 'navigation_text_hover'" onmouseout="this.className='navigation_text'"><strong>Website Homepage:</strong><br />Click <a href="http://www.website.com/index.html">here</a> to view our<br />homepage.</div>
}


There's probably a better way to do this using CSS hover properties, but those can be hard to deal with cross browser-wise.

Winterworks
02-23-2009, 10:50 PM
It's not working...

TigerC10
02-23-2009, 10:53 PM
Wow, really? Do you have javascript turned off or something? Because the "onmouseover" and "onmouseout" properties are reliant on javascript...


Try this instead:

<style type="text/css">
.navigation_text {
margin-left: 43px;
width:155px;
height:48px;
text-decoration: none;
font-size: 12px;
color: #000000;
background: #F8F8FF;
}
.navigation_text:hover {
margin-left: 43px;
width:155px;
height:48px;
text-decoration: none;
font-size: 12px;
color: #000000;
background: #FFFFFF;
}
</style>
<div class="navigation_text"><strong>Website Homepage:</strong><br />Click <a href="http://www.website.com/index.html">here</a> to view our<br />homepage.</div>

Winterworks
02-23-2009, 11:06 PM
Okay, sorry, the first one worked, but when you hover it, then when you move your mouse away, it stays white. I want it to go back to normal when you move.

--------------- Added 1235437700 at 1235437700 ---------------

edit: nvm, it works now! thanks!