Forum Moderators: not2easy

Message Too Old, No Replies

CSS Row and Column highlighting

Is it possible to highlight multiple rows and columns at once?

         

max4

2:22 pm on Feb 3, 2008 (gmt 0)

10+ Year Member



Hi,

I've been searching for the past hour or so now, looking for a way to highlight multiple rows and columns on mouseover at once. I would like to be able to get the following table segment to highlight all at once when a user scrolls over any individual cell:

<tr>
<td colspan="2">
<td rowspan="2">
<td rowspan="2">
<tr>

<tr>
<td>
<td>
<tr>

That is, all td and tr segments highlight the same color when a user scrolls over any cell. If this is possible, how can it be done?

Thanks,
Max

Xapti

4:21 am on Feb 4, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just the one row, or more than one row? It kind of looked like you only wanted one row highlighted there, which would be pretty easy to do. Realize that IE6 does not support :hover for anything other than anchor elements though (you would have to use a javascript workaround).
If you want only 2 complete rows to be selected, that could be done with the adjacent sibling selector, but I don't think that's supported in IE6 or IE7.

You may likely want to use javascript for what you're doing.

If I may ask, why would you need such functionality in the first place, though?

max4

2:49 pm on Feb 4, 2008 (gmt 0)

10+ Year Member



Hi Xapti,

Yes, I would like to highlight two rows at the same time. I don't really need that kind of functionality but I would like to maintain the design of my table while adding that extra bit of attraction to it - I have seen other sites with similar tables sacrificing the design of their table to keep everything in one simple row.

I just looked up adjacent sibling selectors and they don't work properly in IE6 but the issue has been fixed in IE7 (or so I've read). Any ideas on how I could do this in java?

max4

7:53 pm on Feb 4, 2008 (gmt 0)

10+ Year Member



Okay, this isn't the javascript forum so I've created a post in there asking about how this can be done in javascript - any ideas about how I can make this work in css, is the adjacent sibling selector my only option?

lavazza

1:09 am on Feb 5, 2008 (gmt 0)

10+ Year Member



As CSS is for presentation and JS is for behaviour, I think it's a case of using both...

Saying that, I'd be very interested to see a CSS-only solution

Anyhoo... here's a (perhaps clumsy, yet 'functioning'and 'valid') CSS/JS combination:

[pre]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title> Highlight multiple rows </title>
<style type="text/css">
.myHighlight {
color:#fff;
background:#666;
}
.myDefault {
color:#333;
background:#ccc;
}
</style>
<script type="text/javascript">
function changeTo(myId)
{
document.getElementById(myId).className='myHighlight';
}
function changeBack(myId)
{
document.getElementById(myId).className='myDefault';
}
</script>
</head>
<body>
<form name="myFormName" method="get" action=" ">
<h1>
HIGHLIGHT MULTIPLE ROWS
</h1>
<noscript>
Javascript must be enabled for the following section to work as intended
</noscript>
<table border="1">
<tr id="trA">
<td colspan="2" id="a1" class="myDefault" onMouseover="changeTo('a1'); changeTo('a2');" onMouseout="changeBack('a1'); changeBack('a2');">
aOne aOne aOne aOne aOne aOne
</td>
<td rowspan="2" id="a2" class="myDefault" onMouseover="changeTo('a1'); changeTo('a2');" onMouseout="changeBack('a1'); changeBack('a2');">
aTwo aTwo aTwo aTwo aTwo
</td>
<td rowspan="2" id="a3" class="myDefault" onMouseover="changeTo('a3'); changeTo('a4');" onMouseout="changeBack('a3'); changeBack('a4');">
aThree aThree aThree aThree aThree
</td>
<td rowspan="2" id="a4" class="myDefault">
aFour aFour aFour
</td>
</tr>
<tr id="trB">
<td id="b1" class="myDefault" onMouseover="changeTo('b1'); changeTo('b2');" onMouseout="changeBack('b1'); changeBack('b2');">
bOne bOne bOne bOne bOne
</td>
<td id="b2" class="myDefault" onMouseover="changeTo('b1'); changeTo('b2');" onMouseout="changeBack('b1'); changeBack('b2');">
bTwo bTwo bTwo bTwo
</td>
</tr>
<tr id="trC" class="myDefault" >
<td onMouseover="changeTo('trC');" onMouseout="changeBack('trC');">
cOne cOne cOne cOne cOne
</td>
<td>
cTwo cTwo cTwo cTwo
</td>
<td>
cThree cThree cThree cThree cThree cThree cThree
</td>
<td>
cFour cFour cFour cFour cFour
</td>
<td>
cFive cFive cFive cFive cFive
</td>
</tr>
<tr id="trE">
<td id="e1" class="myDefault" onMouseover="changeTo('b1'); changeTo('e1');" onMouseout="changeBack('b1'); changeBack('e1');">
eOne eOne eOne eOne eOne
</td>
<td id="e2" class="myDefault" onMouseover="changeTo('b2'); changeTo('e2');" onMouseout="changeBack('b2'); changeBack('e2');">
eTwo eTwo eTwo eTwo
</td>
<td id="e3" class="myDefault" onMouseover="changeTo('trC'); changeTo('e3');" onMouseout="changeBack('trC'); changeBack('e3');">
eThree eThree eThree eThree
</td>
<td id="e4" class="myDefault" onMouseover="changeTo('a3'); changeTo('a4'); changeTo('e4'); changeTo('e5');" onMouseout="changeBack('a3'); changeBack('a4'); changeBack('e4'); changeBack('e5');">
eFour eFour eFour eFour
</td>
<td id="e5" class="myDefault" onMouseover="changeTo('b1'); changeTo('b2'); changeTo('e5');" onMouseout="changeBack('b1'); changeBack('b2'); changeBack('e5');">
eFive eFive eFive eFive
</td>
</tr>
</table>
</form>
</body>
</html>
[/pre]

Xapti

6:51 am on Feb 5, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There are premade scripts which aren't hard to include into web documents which can emulate support for such things. For instance, "IE7.js" does exactly this for IE6 (and lower). It's also modular, so you can only include parts of the script if you don't want to use all of it's fixes.
(in fact there's a topic going on right now in this forum section about those exact scripts, about the same time you made your post.)

[edited by: Xapti at 6:53 am (utc) on Feb. 5, 2008]

max4

4:01 pm on Feb 5, 2008 (gmt 0)

10+ Year Member



Wow, Lavazza, that works great - thanks a lot. I had some difficulty with IE6 though, it comes standard with javascript disabled - which means most users wont be able to see that effect.

I don't know why microsoft did this, I feel its almost like strapping us all into booster seats to ride a coaster - I wanna enjoy the coaster, not be tied down and padded!

Xapti, I'm not exactly sure what you mean about the premade scripts. Where do I get a hold of IE7.js?

Thanks,
Max

Xapti

6:06 pm on Feb 6, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Umm, I don't keep track a ton of IE stuff, but I'm quite sure javascript is not turned off by default for normal internet pages. Even if it is, virtually all users have enabled it, since too many webpages on the internet absolutely require it.
I think you're likely thinking of the disabled javascript for local page viewing. For some stupid reason they put the default functionality to disable js on local pages, but you can easily correct it. It's only a problem when your pages are on the local machine.

When it comes to IE7.js, google can be your friend. I'm quite sure searching that term gives you all the information you should need at the first result (the homepage of the script, I'd guess)

max4

5:31 pm on Feb 7, 2008 (gmt 0)

10+ Year Member



Wow, thanks Xapti - you answered another question I had. I thought IE was being a &^%$#; I'm really glad it's just a localhost issue and not a general problem.

I've heard of a thing called google but I'm not really sure what it is. Everyone keep saying its a friend, but I'm a bit skeptical. I'm completely joking of course.

Take care,
Max