Html 使用 css 突出显示选定的行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5154955/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 07:01:49  来源:igfitidea点击:

Highlight selected row using css

htmlcss

提问by Null Pointer

How we can highlight selected row in a table using css. Is there any way to do that?

我们如何使用 css 突出显示表格中的选定行。有没有办法做到这一点?

采纳答案by Quentin

tr { background: sky-blue-pink } /* Use a real colour */
tr * { background: transparent; }

where tris a more specific selector to indicate whatever condition you have in the DOM to represent 'selected'. This will probably be a class selector: tr.selected

wheretr是一个更具体的选择器,用于指示您在 DOM 中拥有的任何条件来表示“已选择”。这可能是一个类选择器:tr.selected

回答by Munneson

Assuming that by "selected" you mean "hovered over by mouse":

假设“选定”是指“鼠标悬停”:

tr:hover {background-color: #FF0000}

You could also highlight with things like 'font-weight:bold', 'color: #FF000', etc..

您还可以使用诸如“font-weight:bold”、“color:#FF000”等来突出显示。

回答by Trufa

You just have to do something like:

您只需要执行以下操作:

tr:hover { background: #FCF; }

See thisexample.

请参阅示例。

回答by DHRUV BANSAL

CSS part:

CSS部分:

table.rowHover tr:hover{ background-color: #ccc; }

apply class = "rowHover" on the table

cheers !!!

干杯!!!