Onmouseover cambiar el color de la fila de la tabla

This is my table.

<?php 

while(($result = mysqli_fetch_assoc($query))){
echo  '<tr>';
echo '<td>';
echo $result['serial'];
echo '</td>';
echo '<td>';
echo $result['address'];
echo '</td>';
echo '<td>';
echo '<a href="profile-display.php?name='.$result['name'].'">'.$result['name'].'</a>' ;
echo '</td>';
echo '<td>';
echo $result['postal'];
echo '</td>';
echo '<td>';
echo $result['website'];
echo '</td>';
echo '</tr>';
}

?>

Now I want that if a user moves his mouse over one row, the color should change.

preguntado el 08 de enero de 11 a las 22:01

What have you tried so far? Btw. the code would be much more readable and maintainable if you embed PHP into HTML and not vice versa. -

Don't echo html, use a templating engine or just use <?=var?>. Your code is very hard to understand. -

3 Respuestas

If you don't need to support IE 6, add this to your CSS:

table tr:hover {
    background:orange;
}

Respondido el 09 de enero de 11 a las 01:01

@ryan: Please remember to "accept" this answer if it was helpful. Thanks. :o) - user113716

Haz tu <tr> etiquetas <tr onMouseOver="this.bgColor='#EABF4E';">, o usar table tr:hover en CSS.

Respondido el 09 de enero de 11 a las 01:01

I am a bit of a noob, but I think you need to give the table row a class, then give that class a hover property in your css file.

Add a class to your table row like so:

echo  '<tr class="highlighter">';

You can name it anything, just make sure you use the same name in your css file.

Now, style the class so that it's color changes when a user's mouse hovers over it:

.highlighter:hover {
    background: #ffff99;
 }

Respondido el 09 de enero de 11 a las 01:01

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.