Topic: Problem with colors in a menu

Hello,

On a Web site, I still use <table> and I have a problem.

In a menu, the background-color of a cell changes when the pointer of the mouse is hover and the color of the fonts doesn't change.

I have this in my HTML :

<table cellspacing="0" cellpadding="5">
  <tr>
    <td class="menu" onmouseover="this.className='menu-hover'" onmouseout="this.className='menu'"><a class="menu" href="lien_1.htm">Lien 1</a></td></tr></table>

And in my CSS :

.menu, a.menu:visited
  {
  color: #444;
  background-color: #eee;
  font-weight: bold;
  text-decoration: none;
  }

a.menu:hover
  {
  color: #444;
  background-color: #ddd;
  }

td.menu
  {
  color: #444;
  background-color: #eee;
  width: 140px;
  }

td.menu-hover
  {
  color: #444;
  background-color: #ddd;
  width: 140px;
  }

When the pointer of the mouse passes on the cell, the color of this one changes but the color of the words changes of course only if I pass precisely on the link.

I cannot delete the part CSS referring to the color and the background-color of the link of the menu under penalty of having a "warning" when I try to validate my CSS via the W3C.

---

A solution that I found is to work with property ONCLICK directly in a cell.

In my new HTML I have :

<table cellspacing="0" cellpadding="5">
  <tr>
    <td class="menu" onclick="location='lien_1.htm'" onmouseover="this.className='menu-hover'" onmouseout="this.className='menu'">Lien 1</td></tr></table>

And in my new CSS I have only :

td.menu
  {
  font-weight: bold;
  color: #444;
  background-color: #eee;
  width: 140px;
  }

td.menu-hover
  {
  color: #444;
  background-color: #ddd;
  width: 140px;
  cursor: crosshair;
  }

Everything is OK... but I think that Google and other search engines don't follow links with ONCLICK.

A solution ?

Sorry for the length of my message.

Thanks smile

2

Re: Problem with colors in a menu

The answer was to make the link display: block and give it sufficient padding (or height and width) to fill the cell then you didn't have to bother with the javascript.

Don't worry about that silly warning from the validator, I don't think anybody pays any attention to that.

3 (edited by Rador8 2011-02-27 16:06)

Re: Problem with colors in a menu

Paul wrote:

The answer was to make the link display: block and give it sufficient padding (or height and width) to fill the cell then you didn't have to bother with the javascript.

Hi Paul,

Thanks a lot Paul (the real Paul) !

This is a really good solution to my problem smile

Mmh... but it's ok with Firefox and Opera but with Internet Explorer, the color changes only if the pointer of the mouse is precisely on the link. With Firefox and Opera, no problem, the color changes also if I am just on the line.

I think that it is a bug of IE. Do you think also this ?

4

Re: Problem with colors in a menu

Try this

a.menu, a.menu:visited
  {
  display: block;
  color: #444;
  background-color: #eee;
  font-weight: bold;
  text-decoration: none;
  padding: 5px;
  height: auto !important;
  height: 1%;
  }

Re: Problem with colors in a menu

Paul wrote:

Try this

  height: auto !important;
  height: 1%;

Wow smile
It works now, thanks again.