简体   繁体   English

无法使CSS悬停在表中的TR上工作

[英]Cannot make CSS hover work on TR in table

I am trying to make my table rows highlight when i hover my mouse over them 当我将鼠标悬停在表格行上时,我试图使其突出显示

.Table .Popup tr:hover {
    background-color:red;
}

Seems to work find on TD tags, but I seem to have trouble getting it to work for TR tags : 似乎可以在TD标签上找到工作,但是我似乎很难将其用于TR标签:

Fiddle : 小提琴:

http://jsfiddle.net/kUTDB/2/ http://jsfiddle.net/kUTDB/2/

Any idea what I am doing wrong? 知道我在做什么错吗?

The proper CSS should be this: 正确的CSS应该是这样的:

.Popup tr:hover td {
    background-color:red;
}

.Popup .PopupRow:hover td {
    background-color:red;
}

You can't (reliably) style a <tr> , so you need to apply the style to children <td> s on hover (hence tr:hover td . 您不能(可靠地)设置<tr>样式,因此需要在悬停时将样式应用于子<td>的样式(因此tr:hover td

Additionally, the .Table class doesn't refer to any elements in your fiddle, which may also be causing problems. 此外, .Table类未在提琴中引用任何元素,这也可能会引起问题。

http://jsfiddle.net/kUTDB/12/ http://jsfiddle.net/kUTDB/12/

You can just do: 您可以这样做:

td:hover {
    background-color:red;
}

try like this 这样尝试

.PopupContainer .Popup tr:hover {
    background-color:red;
}

Fiddle 小提琴

Your CSS selector was incorrect: 您的CSS选择器不正确:

Both

table tr:hover {
    background-color:red;
}

and

table .PopupRow:hover {
    background-color:red;
}

will work here. 将在这里工作。

Fiddle: http://jsfiddle.net/kUTDB/7/ 小提琴: http : //jsfiddle.net/kUTDB/7/


if you needed to be very specific, you could use this selector: 如果您需要非常具体,则可以使用以下选择器:

 div.PopupContainer div.Popuptable table tbody tr.PopupRow:hover{ 

However, since longer selectors cost time, the more broad selectors are better. 但是,由于选择器时间越长,选择器越宽越好。 Really, you only need .PopupRow:hover here. 真的,您只需要.PopupRow:hover在这里。

You need to do the td 你需要做TD

tr:hover td {
     background-color:red;
}

As stated on your previous question : 如上一个问题所述

Your CSS selectors are not selecting anything. 您的CSS选择器未选择任何内容。

.Table .Popup tr:hover {
    background-color:red;
}

should be: 应该:

.Popup tr:hover {
    background-color:red;
}

(See: http://jsfiddle.net/kUTDB/4/ ) (请参阅: http : //jsfiddle.net/kUTDB/4/

and

.Table .Popup .PopupRow:hover {
    background-color:red;
}

should be 应该

table tr.PopupRow:hover {
    background-color:red;
}

or 要么

table .PopupRow:hover {
    background-color:red;
}

(See: http://jsfiddle.net/kUTDB/5/ ) (请参阅: http : //jsfiddle.net/kUTDB/5/

Mind you, these will both select the same elements so the selector with more specificity (the second one) will be the one that is actually used. 请注意,它们都将选择相同的元素,因此具有更高特异性的选择器(第二个选择器)将是实际使用的选择器。

Your first selector, .Table .Popup tr:hover will match tr elements that are currently being hovered over and that are descendants of any element with a class of Popup which are in turn descendants of any element of with a class of Table . 您的第一选择器, .Table .Popup tr:hover将匹配tr当前正在盘旋元件与一个类的任何元件的后代Popup其在与一个类的任何元件的转后代Table

Your second selector, .Table .Popup .PopupRow:hover will match any elements with a class of PopupRow that are currently being hovered over and that are descendants of any element with a class of Popup which are in turn descendants of any element of with a class of Table . 您的第二选择器, .Table .Popup .PopupRow:hover将匹配的一类中的任何元素PopupRow当前正在盘旋若干与一类的任何元件的后代Popup它们与一个中的任何元素的后代转Table类。

The markup in your fiddle does not reflect that structure and so nothing is matched by the selectors (which is why your style is not reflected). 小提琴中的标记无法反映该结构,因此选择器无法匹配任何内容(这就是为什么您的样式无法得到反映)。

.Popup tr:hover { background-color:red; .Popup tr:hover {background-color:red;

} This will totally work. 这将完全起作用。

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

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