Jump to content

Alternating rows WITH hover color change? Is it possible?


alexcmm

Recommended Posts

So, I'm finding that Javascript succums to the PHP alternating row color... by that I mean that the Javascript hover will work if I don't use the PHP alternating row colors. Is there a pure PHP way to do both? I really only HAVE to make this work in IE, but cross platform would be cool.

Here's the alt row PHP I have now:

[code]for($i = 0; $i < $numofrows; $i++) {
    $row = mysql_fetch_array($result); //get a row from our result set
    if($i % 2) { //this means if there is a remainder
        echo "<TR bgcolor=\"#F0EEEE\">\n";
    } else { //if there isn't a remainder we will do the else
        echo "<TR bgcolor=\"white\">\n";[/code]
you cannot make row colors change on hover with php. php is a server side language.  everything is parsed on the server and then sent to the client (your browser).  You can use php to alternate the colors, but you need to use javascript to make it change colors when you hover. 
You can also use css to change the colors for hovering.
You only need to specify the class in your html tag, css will do the rest.

[code]
<table>
<tr class="tableHover" bgcolor="white">
<td>some info</td>
<td>some info</td>
</tr>
</table>

=> CSS

tr.tableHover:HOVER {
background-color: #F0EEEE;
}


[/code]
That is not completely true. You can use CSS to make colors change on hover. In IE the hover attribute only works on addresses. If you can enclose each row in an <a> tag (without an "href" tag) with a particular  CSS class, you can use PHP to switch the CSS class to change the hover color.

Ken

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.