Jump to content

Changing the colour of a cell on a rollover?


Solarpitch

Recommended Posts

Hey Guys,

 

Just wondering how you change the colour of a cell based on a rollover? http://www.dynamicdrive.com has the perfect example. On there main menu on the right it changes from white to green when you rollover . . just wondering how its done?

 

I can do rollover's in css with hover and that, but I cant seem to get it to work when I apply it to a cell?

 

Cheers!

Link to comment
Share on other sites

Like this?:

<style type="text/css">
body {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 80%;
}

#nav {
list-style-type: none;
display: block;
padding: 0;
width: 100px;
}

#nav a {
text-decoration: none;
color: green;
font-weight: bold;
display: block;
}

#nav > li {
margin-bottom: 5px;
border-bottom: 1px solid #AAA;
}

#nav a:hover {
color: white;
background: green;
}
</style>

<ul id="nav">
<li><a href='#'>Link 1</a></li>
<li><a href='#'>Link 2</a></li>
<li><a href='#'>Link 3</a></li>
<li><a href='#'>Link 4</a></li>
<li><a href='#'>Link 5</a></li>
</ul>

Link to comment
Share on other sites

Sure. Assumption: the links are directly in the TD, there are no intervening

elements.

 

td.hover {

  styles for hovered TD

}

 

window.onload = function ()

{

  var x = document.getElementById('id_of_nav_table');

  var y = x.getElementsByTagName('A');

  for (var i=0;i<y.length;i++)

  {

    y.onmouseover = function () {this.parentNode.className='hover'}

    y.onmouseout = function () {this.parentNode.className=''}

  }

}

 

Now the className of the TD changes onMouseOver on the link to 'hover' and

the browser applies the special styles. onMouseOut the className is removed

again and the TD reverts to the standard styles.

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.