Solved

Changing Table Cell color at a Mouse Over event

Posted on 2004-04-05
9
28,437 Views
Last Modified: 2012-06-27
Hi,
  Does anyone know if it is possible to change color of an entire table cell on a Mouse over event. What I want to do is instead using a:hover for the link I want to use CSS to change color of the entire table cell of the link. I know I can do this using Images rollovers or javascript, but want to find out if there is anyway to do it in CSS.

Thanks
0
Comment
Question by:BrijBhasin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 35

Assisted Solution

by:YZlat
YZlat earned 100 total points
ID: 10758283
use javascript:
<html>
<head>
<script language="javascript".
<!--
function changeCellBG(el, myColor) {
      el.style.background =myColor;
}

//-->
</script>
</head>
<body>
<table cellspacing="1" border="1">
<tr style="background:red;">
<td width="200" height="20" onMouseOver="changeCellBG(this, 'pink');"></td><td width="200" onMouseOver="changeCellBG(this, 'pink');"></td><td width="200" onMouseOver="changeCellBG(this, 'pink');"></td>
</tr>
<tr style="background:orange;">
<td width="200" height="20" onMouseOver="changeCellBG(this, 'pink');"></td><td width="200" onMouseOver="changeCellBG(this, 'pink');"></td><td width="200" onMouseOver="changeCellBG(this, 'pink');"></td>
</tr>
<tr style="background:yellow;">
<td width="200" height="20" onMouseOver="changeCellBG(this, 'pink');"></td><td width="200" onMouseOver="changeCellBG(this, 'pink');"></td><td width="200" onMouseOver="changeCellBG(this, 'pink');"></td>
</tr>

</table>
</body>
</html>
0
 
LVL 9

Accepted Solution

by:
lombardp earned 150 total points
ID: 10758325
Similar to Yzlat, but CSS-based.

<html>
<head>
<style>
.classover {background-color: #ff0000;}
</style>
</head>

<body>
<table>
<tr>
   <td  onmouseover="this.className='classover'" onmouseout="this.className=''">aaa</td>
   <td  onmouseover="this.className='classover'" onmouseout="this.className=''">aaa</td>
</tr>
<tr>
   <td  onmouseover="this.className='classover'" onmouseout="this.className=''">aaa</td>
   <td  onmouseover="this.className='classover'" onmouseout="this.className=''">aaa</td>
</tr>
</table>

</body>
</html>
0
 
LVL 35

Expert Comment

by:YZlat
ID: 10758347
<style type="text/css">

.over { background-color:pink; }
.out  { background-color:red; }

</style>
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 35

Expert Comment

by:YZlat
ID: 10758352
<html>
<head>
<title>untitled</title>
<style type="text/css">

.over { background-color:pink; }
.out  { background-color:red; }

</style>

</head>
<body>
<table cellspacing="1" border="1">
<tr style="background:red;">
<td width="200" height="20"  onmouseover="this.className='over'" onmouseout="this.className='out'"></td><td width="200" onmouseover="this.className='over'" onmouseout="this.className='out'"></td><td width="200" onmouseover="this.className='over'" onmouseout="this.className='out'"></td>
</tr>
<tr style="background:red;">
<td width="200" height="20" ></td><td width="200"></td><td width="200"></td>
</tr>
<tr style="background:red;">
<td width="200" height="20"></td><td width="200"></td><td width="200"></td>
</tr>

</table>
</body>
</html>
0
 
LVL 35

Expert Comment

by:YZlat
ID: 10758360
sorry  lombardp, my last solution is almost identical to yours. - I did not refresh the page
0
 
LVL 9

Expert Comment

by:lombardp
ID: 10758499
:)
0
 

Author Comment

by:BrijBhasin
ID: 10761195
Hi,
  Your solutions worked great accept for when mouseout happens the mouse over color remains there instead of switching back to the original color. Any idea why this is happening?

0
 

Expert Comment

by:lakshmanatessar
ID: 11396605
hello.
this script works well but i want a slight imprvisation. when clikced on  a link that bg color has to change to some other color and has to stay like that. when clicked on another cell then the previously clicked cell's bg color returns to the normal one and the latest clicked one changes its color. in this process the other cells has to be in the same features that changing bg color when hovered and returning to normal color when mouse is not hovered.
can anyone help?

thanks.
Lakshman Pilaka.
0
 
LVL 15

Expert Comment

by:JackOfPH
ID: 14916733
ping
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Creating a CSS block that only applies to printing By default, all of your CSS applies to every possible view of your page - whether on screen, printed, landscape, touch-screen, or whatever.  You can, however, add CSS that only applies under certai…
When writing CSS, there are a few simple rules that will make your life easier.    1. Using ‘* {box-sizing:border-box;}’. Using this will wrap all your elements in a nice little compact box-model that will give you the width you want, like so... …
In this Micro Tutorial users will learn how to embed custom fonts into websites using @font-face in CSS Select a font: Ensure the EULA allows you to use @font-face: Download the font: Get the browser-compatible files you need: Edit your CSS       - Name …
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question