如何将背景样式覆盖回原始状态?

时间:2013-06-03 14:09:19

标签: html css background-color

我有以下情况:

.table_green {
background: #B4E391;
}
.data_table tbody tr:hover {
background-color: #fff;
cursor: pointer;
}
.unclickable_table tbody tr:hover {
background-color: inherit;
cursor: default;
}

现在tr原来是绿色,我希望当一个表设置class='data_table unclickable_table'时,将其悬停在trtable_green上,{ {1}}属性不会更改并保持绿色,但background-color似乎不起作用

示例html:

inherit

或者这个小提琴:http://jsfiddle.net/nyDNc/1/

任何帮助?

3 个答案:

答案 0 :(得分:1)

这是一个解决方案,希望能够在你的结构中运行,因为它取决于你如何设置表元素的样式。

inherit将无法正常工作,因为它继承自背景为none的表。相反,您可以设置tr并在悬停时更改td的颜色,以便它具有要继承的上下文。

请参阅工作示例here on JSFiddle

CSS是:

.table_green {
  background: #B4E391;
}
.data_table tbody tr:hover td {
  background-color: #fff;
  cursor: pointer;
}
.unclickable_table.data_table tbody tr:hover td {
  background-color: inherit;
  cursor: default;
}

答案 1 :(得分:0)

为什么要添加第二个类以覆盖第一个类的效果。为什么不直接删除不希望效果的行上的'data_table'类。

答案 2 :(得分:0)

我不确定我很了解你,但是

DEMO IS HERE:
http://jsfiddle.net/nyDNc/1/