CSS 如何为表格定义一个类来控制表格行的样式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21291762/
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
How to define a class for table to control the style of table rows
提问by newbie
I'm wondering if I can define a class that could also control the row styles within the table.
我想知道是否可以定义一个还可以控制表中行样式的类。
Lets say I define a class "aTable"
假设我定义了一个类“aTable”
.aTable
{
width:800px;
border-spacing:2px;
}
I also want to define the row styles. So when I assign this class to a table, all the rows in that table would follow the design, let say background-color:#e9e9e9;
我还想定义行样式。因此,当我将此类分配给一个表时,该表中的所有行都将遵循设计,比如 background-color:#e9e9e9;
回答by dfsq
You can achieve it like this:
你可以这样实现:
.aTable {
width: 800px;
border-spacing: 2px;
}
.aTable tr {
background-color: #DDD;
}
回答by mboldt
To give a whole row a background-color your would assign the background-color to each cell in that row, i.e.
要为整行提供背景颜色,您可以为该行中的每个单元格分配背景颜色,即
.aTable tr td { background-color: #e9e9e9: }
You can always select specific classes or elements within a css class definition like that.
您始终可以像这样在 css 类定义中选择特定的类或元素。