php - Onmouseover change color of table row - Stack Overflow

This is my table. <?php while(($result = mysqli_fetch_assoc($query))){echo'<tr>';

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.

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.

Share Improve this question asked Jan 8, 2011 at 22:19 sarthaksarthak 2971 gold badge8 silver badges16 bronze badges 2
  • 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. – Felix Kling Commented Jan 8, 2011 at 22:22
  • Don't echo html, use a templating engine or just use <?=var?>. Your code is very hard to understand. – the_drow Commented Jan 8, 2011 at 22:32
Add a ment  | 

3 Answers 3

Reset to default 5

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

table tr:hover {
    background:orange;
}

Make your <tr> tags <tr onMouseOver="this.bgColor='#EABF4E';">, or use table tr:hover in CSS.

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;
 }

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742319252a4421469.html

相关推荐

  • php - Onmouseover change color of table row - Stack Overflow

    This is my table. <?php while(($result = mysqli_fetch_assoc($query))){echo'<tr>';

    11小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信