CSS html table hover

Hi experts

I have a html table. This is the code.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">

#MyTable tr:first-child:hover TD{ 
      background: #FF0000;
}

 #MyTable TR:hover TD
 {
      background: #0000FF;
}

</style>
</head>

<body>
<table width="800" border="0" id="MyTable">
  <tr>
    <td>TeamID</td>
    <td>TeamCity</td>
    <td>TeamName</td>
  </tr>
  <tr>
    <td>1</td>
    <td>Los Angeles</td>
    <td>Lakers</td>
  </tr>
  <tr>
    <td>2</td>
    <td>Miami</td>
    <td>Heat</td>
  </tr>
  <tr>
    <td>3</td>
    <td>Sacramento</td>
    <td>Kings</td>
  </tr>
  <tr>
    <td>4</td>
    <td>Houston</td>
    <td>Rockets</td>
  </tr>
</table>
</body>
</html>

Open in new window


This table has 5 rows. When you hover over rows 2 through row 5. They are highlighted blue.
When you hover over row 1 it is highlighted red.

How would I change my css code to do the following:

When I hover over rows 2 through row 5. They are highlighted blue.
But when I hover over row 1, row 1 shouldn't be highlighted at all.
In this particular example I know I could just switch red color to white because my background is white, but I want to know if there is a way to do it like say have the highlight of row 1 to be transparent or not highlight row 1 at all.

I only want rows 2 through 4 to be highlighted blue when I hover my mouse over those rows..
LVL 1
maqskywalkerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ArgentiCommented:
Here you go

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">

#MyTable thead tr:first-child:hover TD{ 
      background: #FF0000;
}

#MyTable tfoot tr:first-child:hover TD{ 
      background: none;
}

#MyTable TR:hover TD
 {
      background: #0000FF;
}


</style>
</head>

<body>
<table width="800" border="0" id="MyTable">
  <thead>
  <tr>
    <td>TeamID</td>
    <td>TeamCity</td>
    <td>TeamName</td>
  </tr>
  </thead>
  <tbody>
  <tr>
    <td>1</td>
    <td>Los Angeles</td>
    <td>Lakers</td>
  </tr>
  <tr>
    <td>2</td>
    <td>Miami</td>
    <td>Heat</td>
  </tr>
  <tr>
    <td>3</td>
    <td>Sacramento</td>
    <td>Kings</td>
  </tr>
  </tbody>
  <tfoot>
  <tr>
    <td>4</td>
    <td>Houston</td>
    <td>Rockets</td>
  </tr>
  </tfoot>
</table>
</body>
</html>
                                  

Open in new window


*Edited
0
Chris StanyonWebDevCommented:
If you want the first row to be transparent, then just set it to be transparent!

#MyTable tr:first-child:hover td { background-color: transparent; }
#MyTable tr:hover td { background-color: blue; }

Open in new window

You could use a CSS3 selector to do the whole thing:

#MyTable tr:not(:first-child):hover td { background-color:blue; }

Open in new window

Or you could code your table in a more semantic way - using thead, tbody, tfoot and th:

<table id="myTable">
<thead>
  <tr>
    <th>Header</th>
  </tr>
</thead>
<tbody>
  <tr>
    <td>Test Case</td>
  </tr>
</tbody>
</table>

#myTable tbody tr:hover td { background-color: blue; }

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
CSS

From novice to tech pro — start learning today.