繁体   English   中英

PHP和CSS:如何获得表的每一行的悬停效果?

[英]PHP & CSS: How to get hover effect for each row of a table?

我正在使用此代码显示事件。 每个事件都是可单击的,但是为此我确实需要背景色的悬停效果。 也许没有JavaScript也可能吗?

<table class="tableLine">
<tr>
<th>Wann?</th>
<th>Was?</th>
<th>Wer?</th>
<th>Wo?</th>
</tr>

<?php
$all_events = array();
$ten_events = array();

for($i = 0; $events = mysql_fetch_object($events_resource); $i++){

if($i < 9){

    $ten_events[] = $events;

}

$all_events[] = $events;

}  

$i = 0;

foreach($ten_events as $event){ 

$row = $i % 2;

echo "<tr onclick=\"window.location.href = '?page=single_event&amp;id=$event->id'\" style=\"cursor: pointer;\">
        <td class='row_{$row}'>{$event->de_date}</td></a>
        <td class='row_{$row}'>{$event->category}</td>
        <td class='row_{$row}'>{$event->who}</td>
        <td class='row_{$row}'>{$event->location}</td>
      </tr>";

$i++;

} 
?>

的CSS

这是我的行的CSS代码。

.tableLine {
font-family: Verdana,Arial,sans-serif;
font-weight: normal;
font-size: 10px;
width: 614px;
border: 0;
padding: 0;
border-spacing: 0;
text-align: left;
}

.tableLine th {
background-color: #990000;
color: #f3f2ea;
font-weight: bold;
}

.row_0 {
background-color: #424140;
padding: 3px 5px 3px 5px;
color: #f3f2ea;
}

.row_1 {
background-color: #555352;
padding: 3px 5px 3px 5px;
color: #f3f2ea;
}

.tableLine tr:hover {
background: #990000;
}

使用CSS:

 tr:hover { background: #CCC; } 

尝试这个:

  1. td删除class='row_{$row}'并将其放入tr标签
  2. 然后替换您的css的这一部分:

/ ** /

.row_0 {
background-color: #424140;
padding: 3px 5px 3px 5px;
color: #f3f2ea;
}

.row_1 {
background-color: #555352;
padding: 3px 5px 3px 5px;
color: #f3f2ea;
}

有了这个:

.row_0 {
   background-color: #424140;
}

.row_1 {
   background-color: #555352;
}

.row_0:hover, .row_1:hover {
   background-color: #EEE; /* highlight row */
}

.tableLine tr td {
   padding: 3px 5px 3px 5px;
   color: #f3f2ea;
}

尝试使用CSS

table tr:hover{background:#eee;}​

如果您还希望突出显示每一列,则可以给td每列一个唯一的类,并使用以下内容。 (jQuery的)

$("td").hover(
    // Mouse Over Function
    function () {
        $('.'+$(this).attr('class')).each(function() {
            $(this).css("background","#FAFAFA");
        });
        $(this).parent().children("td").each(function() {$(this).css("background","#FAFAFA")});
        $(this).css("background","#FAEEFA");
    },
    // Mouse Out Function
    function () {
        $('.'+$(this).attr('class')).each(function() {
            $('.'+$(this).attr('class')).css("background","#FFFFFF");
        });
        $(this).parent().children("td").each(function() {$(this).css("background","#FFFFFF")});
    });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM