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

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

Change the color of all the td inside a table class in CSS

htmlcss

提问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

tdis 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 tdis direct child of trand tris direct child of table.

在这种情况下td是 的直接子代trtr的直接子代table

回答by user3178594

table.items tdor table.items > tr > tdwill do the required job as suggested by others already.

table.items td或者table.items > tr > td将按照其他人的建议完成所需的工作。

But, may be.. giving border-bottomto rows instead of cells.. i.e, giving it to table.items > trwill 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 > tdyou 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 建议的那样)!