简体   繁体   English

CSS tr悬停,不包含某些类的tr

[英]CSS tr hover excluding tr with certain class

I have a table which is populated by some JS on opening and as part of that, section headings are given a column span across the whole table as well as a classname of "section". 我有一个表,该表在打开时由一些JS填充,并且其中的一部分为节标题提供了整个表的列跨度以及“节”的类名。 I verified this by an alert in the onmouseover hook for the tr elements which echoed the classname. 我通过在onmouseover钩子中发出警报,以回显类名的tr元素来验证这一点。 The classname definitely takes. 该类名肯定需要。

I have some CSS like this... 我有一些这样的CSS ...

tr:hover {
    background-color: #FF9966
}
thead tr:hover, tr.section:hover {background-color: #DACFE5;!important}

The roll-over works fine and excludes the thead children, but I cant get it to exclude "section" class tr's. 翻转效果很好,并且排除了thead儿童,但我无法排除“ section”类tr的影响。

What syntax do I need in the CSS to achieve this? 我需要在CSS中使用什么语法来实现这一目标?

The table template is... 表格模板是...

<table id="myTable" border="1" class="indent">
  <thead>
    <tr> 
      <th colspan="3">Joe's Cafe Menu</th>
    </tr>
    <tr>
      <th>Select</th>
      <th>Item</th>
      <th>Price</th>
    <tr>
  </thead>
  <tbody>
  </tbody>
</table>

EDIT: 编辑:

Problem was case sensitivity. 问题是区分大小写。 A rookie error I guess. 我猜是菜鸟错误。 classname was being echoed in the alert but the member referenced by the CSS is className. 在警报中回显了classname,但是CSS引用的成员是className。 I fixed that and now its fine. 我已经解决了,现在还好。

This CSS works like a charm... 这个CSS就像一个魅力...

tbody tr:not(.section):hover {
    background-color: #FF9966
}

For reasons I don't understand, this CSS fails to exclude the header... 由于我不明白的原因,此CSS无法排除标头...

tr:not(.section):hover {
    background-color: #FF9966
}
thead tr:hover td {background-color: #DACFE5;}

Which is academic really since its a bit of a hack. 这真的很学术,因为它有点破烂。

tr:not(.section):hover { background-color: #FF9966 }

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

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