Click to See Complete Forum and Search --> : tr:hover backgrond, with one class?


AzaraT
01-16-2008, 11:55 AM
Hi There!

I got this problem, I want to make a table so that when you mouseover the table rows, it will change backgroundcolor. The thing is, the top row, should not be affected, meaning it wont change backgroundcolor on mouseover. So I thought I would make the other rows, a class and make it apply to that class only, however, I just cant get this working.

I have tried a few differnt things like

.class tr:hover {}
tr.class tr:hover{}

but I just cant get this to work, hope someone can help me out here!
Thanks!

WebJoel
01-16-2008, 12:14 PM
http://www.vladdy.net/demos/iepseudoclassesfix.html

If you have problems figuring this out, come back with your TABLE code and tell me more. This solution is fairly simple to implement.

AzaraT
01-16-2008, 12:29 PM
well, I dont think it has anything to do with this, because im not even using IE...


<html>
<head>
<title>Udgivelser i denne måned</title>

<style type="text/css">
tr:hover
{
background-color:#ccd5e8;
}

td a {
display: block;
}

</style>

</head>

<body>

<table padding="0" cellpadding="0" cellspacing="0">
<tr margin="0" padding="0" >
<th align="left">Spil</th>
<th align="left">Platform</th>
<th align="left">Categori</th>
<th align="left">Udgivelses Dato</th>
</tr>
<xsl:for-each select="Games/Game">
<tr margin="0" padding="0" class="spil">
<td><xsl:value-of select="Title" /></td>
<td><xsl:value-of select="Platform/Title" /></td>
<td><xsl:value-of select="Category" /></td>
<td><xsl:value-of select="ReleaseDates/Scandinavia" /></td>
</tr>
</xsl:for-each>

</table>
</body>
</html>

Now it is chaging background on hover on every tablerow, I only want it to be the table row with the class="spil". I don't think that fix will help ?

WebJoel
01-17-2008, 11:50 AM
well, I dont think it has anything to do with this, because im not even using IE...

[html]<html>
<head>
<title>Udgivelser i denne måned</title>

<style type="text/css">
tr:hover
{
background-color:#ccd5e8;
}
.... Which is exactly my point: you cannot get the pseudo-class ":hover" to work in IE in any element except an "<a>" (anchor), without the little javascript hacky that I pointed out. :) You have to 'trick' IE into handling this as a "onMouseOver/onMouseOut", and this script does it. That you are using TABLE layout makes it all the easier to set up from the examples given.

AzaraT
01-18-2008, 04:55 AM
hmm what I got now is this

<html>
<head>
<title>Udgivelser i denne måned</title>

<style type="text/css">

tbody tr:hover,tbody tr.hover
{ background: #ccd5e8f;
}

tr, td
{ behavior: url('fix.htc');
}

td a {
display: block;
}

td:hover, td.hover
{ background: #ccd5e8;
}

</style>

</head>

<body>

<table padding="0">
<tr margin="0" padding="0">
<th align="left">Spil</th>
<th align="left">Platform</th>
<th align="left">Categori</th>
<th align="left">Udgivelses Dato</th>
</tr>
<xsl:for-each select="Games/Game">
<tr margin="0" padding="0">
<td><xsl:value-of select="Title" /></td>
<td><xsl:value-of select="Platform/Title" /></td>
<td><xsl:value-of select="Category" /></td>
<td><xsl:value-of select="ReleaseDates/Scandinavia" /></td>
</tr>
</xsl:for-each>

</table>
</body>
</html>

But this only highlight the td element, I want it to hightlight the whole table row.. I can't really figure it out, there is no real example code on that site..

WebJoel
01-18-2008, 06:45 AM
<html>
<head>
<title>Udgivelser i denne måned</title>

<style type="text/css">

tbody tr:hover,tbody tr.hover
{ background: #ccd5e8f;
}

tr, td
{ behavior: url('fix.htc');
}

td a {
display: block;
}

td:hover, td.hover
{ background: #ccd5e8;
}

</style>

</head>

<body>

<table padding="0">
<tr margin="0" padding="0">
<th align="left">Spil</th>
<th align="left">Platform</th>
<th align="left">Categori</th>
<th align="left">Udgivelses Dato</th>
</tr>
<xsl:for-each select="Games/Game">
<tr margin="0" padding="0">
<td><xsl:value-of select="Title" /></td>
<td><xsl:value-of select="Platform/Title" /></td>
<td><xsl:value-of select="Category" /></td>
<td><xsl:value-of select="ReleaseDates/Scandinavia" /></td>
</tr>
</xsl:for-each>

</table>
</body>
</html>

But this only highlight the td element, I want it to hightlight the whole table row.. I can't really figure it out, there is no real example code on that site.. You'd have to VIEW -SOURCE, but yes, the code is there. :)
Unless you re-named the script (and I assume that you downloaded or copied the javascript and that it is in the correct path as referanced), this is probably not correct and thus, not working. I believe that the script was called "IEfix.htc". There shouldn't be any reason to rename the file (but it's okay if you did, you just have to be consistant).

I might have enough of your TABLE now to fix this up for you. I'll try to get it back here sometime today.. :)

Also, you have invalid color here... Six numbers, -not seven.

WebJoel
01-18-2008, 07:56 AM
(bak) :

<html>
<head>
<title>Udgivelser i denne måned</title>

<style type="text/css">

tbody tr:hover,tbody tr.hover
{ background-color: #ccd5e8;
}

tr, td
{ behavior: url('IEfix.htc');
}

td a {
display: block;
}

tr,th,td {text-align:center; padding:0 10px 0 10px;}


td:hover, td.hover
{ background-color: red/*#ccd5e8*/; color:white;
}

</style>

</head>

<body>

<table padding="0" border="1">
<tr margin="0" padding="0">
<th align="left">Spil</th>
<th align="left">Platform</th>
<th align="left">Categori</th>
<th align="left">Udgivelses Dato</th>
</tr>
<xsl:for-each select="Games/Game">
<tr margin="0" padding="0">
<td><xsl:value-of select="Title" />test 1</td>
<td><xsl:value-of select="Platform/Title" />test 2</td>
<td><xsl:value-of select="Category" />test 3</td>
<td><xsl:value-of select="ReleaseDates/Scandinavia" />test 4</td>
</tr>
</xsl:for-each>

<tr margin="0" padding="0">
<td><xsl:value-of select="Title" />test 5</td>
<td><xsl:value-of select="Platform/Title" />test 6</td>
<td><xsl:value-of select="Category" />test 7</td>
<td><xsl:value-of select="ReleaseDates/Scandinavia" />test 8</td>
</tr>

<tr margin="0" padding="0">
<td><xsl:value-of select="Title" />test 9</td>
<td><xsl:value-of select="Platform/Title" />test 10</td>
<td><xsl:value-of select="Category" />test 11</td>
<td><xsl:value-of select="ReleaseDates/Scandinavia" />test 12</td>
</tr>

</table>
</body>
</html>
AND the below code, saved as "IEfix.htc" under "All Files", makes this work. I added some "<tr>s" with "<td>s" to verify that it works.
Be sure to manually add the ".htc" and SAVE AS "All Files", or else you will pick-up an unwanted extention, like "IEfix.htc.js", which will not work.

"IEfix.htc" file goes in same directory as page (index.html)..<PUBLIC:ATTACH EVENT="onmouseover" ONEVENT="DoHover()" />
<PUBLIC:ATTACH EVENT="onmouseout" ONEVENT="RestoreHover()" />
<PUBLIC:ATTACH EVENT="onmousedown" ONEVENT="DoActive()" />
<PUBLIC:ATTACH EVENT="onmouseup" ONEVENT="RestoreActive()" />
<SCRIPT LANGUAGE="JScript">
function DoHover()
{ element.className += ' hover';
}

function DoActive()
{ element.className += ' active';
}

function RestoreHover()
{ element.className = element.className.replace(/\bhover\b/,'');
}

function RestoreActive()
{ element.className = element.className.replace(/\bactive\b/,'');
}
</SCRIPT> What we are doing, is instructing brain-dead Internet Exploder how to handle the pseudo-class as a 'onMouseOver/onMouseOut' event. "Compliant browsers" would not need this, and never see this script (or, do not act any differantly because of it..)

-I just examined this in IE and Fx: it works for BOTH browsers, which is what you want it to do. :)

Lazer
01-19-2008, 07:02 AM
Hi
If you want ALL rows to be the same create:
<style>
td{background-color: white;}
td:hover{background-color: red;}
</style>

If you wand EACH line to have DIFERENT colors you MUST create a style for EACH ONE
<style>
.line1{background-color: blue;}
.line1:hover{background-color: brown;}
.line2.....
.line2:hover...
.
.
.
</style>

In the lines add <td class=line1>......</td>
<td class=line2>.......</td>

GoodLuck!

AzaraT
01-20-2008, 09:12 AM
Lazer, that gives no resaults at all, nothing happends when you mouse over.

And Webjoel, your method is not working either, the first row, is still highligted when you mouse over which was the problem I had when i started out. (http://zorps.dk/release_list/release_list2.asp)

Thanks for helping....