Html 在 CSS 中更改表类中所有 td 的颜色
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21143450/
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
Change the color of all the td inside a table class in CSS
提问by siren_dev
I am trying to select all the bottom borders inside a table, and turn them gray, without having to assign a class to each td. So far what I have come up with is this, but it does not work:
我试图选择表格内的所有底部边框,并将它们变成灰色,而不必为每个 td 分配一个类。到目前为止,我想出的是这个,但它不起作用:
table.items {
border: 1px solid #42536f;
}
table.items > td {
border-bottom: 1px solid #CCC;
}
Basically, I want to be able to just use the "items" class for the entire table, and have all the bottom borders show up gray, and the outside border show up that dark blueish color I chose.
基本上,我希望能够对整个表格使用“items”类,并使所有底部边框显示为灰色,而外部边框显示为我选择的深蓝色。
Any suggestions?
有什么建议?
Thank you :-)
谢谢 :-)
回答by Pranav C Balan
td
is not the direct child of the table
td
不是 table
table.items{
border:1px solid #42536f;
}
table.items td{
border-bottom:1px solid #CCC;
}
Here all td elements inside the table will select.
这里表内的所有 td 元素都将被选中。
or
或者
table.items{
border:1px solid #42536f;
}
table.items>tr>td{
border-bottom:1px solid #CCC;
}
In this case td
is direct child of tr
and tr
is direct child of table
.
在这种情况下td
是 的直接子代tr
和tr
的直接子代table
。
回答by user3178594
table.items td
or table.items > tr > td
will do the required job as suggested by others already.
table.items td
或者table.items > tr > td
将按照其他人的建议完成所需的工作。
But, may be.. giving border-bottom
to rows instead of cells.. i.e, giving it to table.items > tr
will give a better look. I am not sure if that is what you are looking for :)
但是,可能是.. 给border-bottom
行而不是单元格.. 即,给它table.items > tr
会更好看。我不确定这是否是您要找的 :)
回答by Moni
With table.items > td
you say:
和table.items > td
你说:
Every tdthat is a directchild of table.items
作为table.items的直接子项的每个td
which is never given, because there's always a <tr>
between.
这是从来没有给出的,因为总是有一个<tr>
之间。
Try using table.items td
(like Pranav Ram suggested)!
尝试使用table.items td
(就像 Pranav Ram 建议的那样)!