Solved

Changing Table Cell color at a Mouse Over event

Posted on 2004-04-05
9
28,414 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
9 Comments
 
LVL 35

Assisted Solution

by:YZlat
YZlat earned 100 total points
Comment Utility
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
Comment Utility
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
Comment Utility
<style type="text/css">

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

</style>
0
 
LVL 35

Expert Comment

by:YZlat
Comment Utility
<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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 35

Expert Comment

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

Expert Comment

by:lombardp
Comment Utility
:)
0
 

Author Comment

by:BrijBhasin
Comment Utility
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
Comment Utility
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
Comment Utility
ping
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

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... …
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now