我有以下代码,显示一个PHP表单和一个PHP关联数组的计数。一个表可以由10行(这是变量)有多达10列:跳过悬停的每一个其他单元格与高亮显示在CSS
| col1 | col2 | col3 | col4 |
|-------|------|-------|------|
| word1 | 50 | word4 | 25 |
| word2 | 44 | word5 | 21 |
| word3 | 39 | word6 | 16 |, etc.
CSS的亮点和突出悬停个人<td>
细胞。但是,我需要悬停/突出显示/下划线才能在单词上使用<td>
单元 - 而不是数字。单词总是在奇数列中 - 数字总是在偶数列中。
你可以请建议的代码将做到这一点?我读过,我可能需要在jQuery中执行此操作,因为与悬停有关的浏览器问题。这是迄今为止我所拥有的。先谢谢你。 :)
?>
<table id="word-table">
<?echo "<th>Word Counts</th>";?>
<tbody>
<?
foreach ($rows as $cols) {
echo '<tr><td>' . implode('</td><td class="nth-child(2n-1)">', $cols) . '</td></tr>';
}
?>
</tbody>
</table>
<?
#word-table td:nth-child(2n-1) {
background: #CCFFCC;
}
#word-table td:nth-child(2n) {
display: block;
background: #CCE0FF;
margin-right: 7px;
text-align: center;
}
#word-table tbody td:hover
{
cursor: hand;
cursor: pointer;
color: blue;
text-decoration: underline;
background: #FFFFCC;
}
'第n-child'没有为IE8或更少的支持,在大多数的情况下,我会假设OP要求它为
Neverever
@Neverever工作 - 我把caniuse.com的链接 - 他们可以决定这个答案是否有用并适合他们的目的。在我的工作中,我不支持IE8,Google(就他们的应用而言)也不支持。 – ahren
使用'nth-type-type' http://css-tricks.com/the-difference-between-nth-child-and-nth-of-type/ – CraigTeegarden