简体   繁体   English

选择行(悬停)后,CSS会更改整个行单元格的背景

[英]CSS change entire row cell backgrounds when row is selected (hover)

I have a table which has a different colour when you hover over the row. 当您将鼠标悬停在行上时,我有一个具有不同颜色的表。 This works perfectly but I also have CSS backgrounds in each cell on the row. 这很完美,但是我在行的每个单元格中都有CSS背景。 The background image changes upon hover on each cell currently but as the row colour changes you cannot see the background image in each field unless you hover over the specific cell. 当前,当悬停在每个单元格上时,背景图像发生变化,但是随着行颜色的更改,除非将鼠标悬停在特定的单元格上,否则您将无法在每个字段中看到背景图像。

Can this be solved via CSS or can anyone provide a javascript line to change this. 可以通过CSS解决此问题,还是可以提供任何JavaScript代码来更改此设置。

In the image below you can see on the left I'm hovering over the second column and on the right the 4th column. 在下面的图像中,您可以在左侧看到我悬停在第二列上,而在右侧则徘徊在第四列上。

Basically i want to have all the ticks go white when hover over the row. 基本上,我希望悬停在行上时所有刻度都变白。 I know you guys can help!! 我知道你们可以帮忙!

在此处输入图片说明

Thanks guys. 多谢你们。

Yes, you can with CSS. 是的,您可以使用CSS。 You should post your code btw... 您应该在之后发布您的代码...

Add the rule triggered by TR hovering, but acting on TD s. 添加由TR悬停触发但作用于TD的规则。

Assuming you have a class "ok" on TD s with the black V mark, and a class "ko" on TD s with the X red mark: 假设你有一个class "ok"TD s的黑色V标记和class "ko"TD与X红色标记S:

tr:hover td.ok {
  color: white;
  background-color: black;
}

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

Try to apply the Descendant Selector : 尝试应用后代选择器

tr:hover td .tick { background-image: url('white-tick.png') }

This will apply the style for any element with the class tick which is a child of a td that is itself a child of a tr with the mouse over it. 这将对样式为tick任何元素应用样式,该元素是td的子元素,而td的子元素本身是tr的子元素,鼠标悬停在其上。

For this to work, you need to implement your ticks using background-image and not with img element (if you use img , the image will be on top of the background and the code above won't be visible). 为此,您需要使用background-image而不是img元素来实现刻度(如果使用img ,则图像将位于背景顶部,并且上面的代码将不可见)。

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

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