Html 将样式应用于第一行的单元格
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10450221/
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
Apply style to cells of first row
提问by xperator
It should be very simple but I can't figure it out.
它应该非常简单,但我无法弄清楚。
I have a table like this :
我有一张这样的桌子:
<table class="category_table">
<tr><td> blabla 1</td><td> blabla 2 </td></tr>
<tr><td> blabla 3 </td><td> blabla 4 </td></tr>
</table>
I want to make td
tags of first tr
row have vertical-align
. But not the second row.
我想让td
第一tr
行的标签有vertical-align
. 但不是第二行。
.category_table td{
vertical-align:top;
}
回答by BoltClock
Use tr:first-child
to take the first tr
:
使用tr:first-child
采取先tr
:
.category_table tr:first-child td {
vertical-align: top;
}
If you have nested tables, and you don't want to apply styles to the inner rows, add some child selectors so only the top-level td
s in the first top-level tr
get the styles:
如果您有嵌套表,并且不想将样式应用于内部行,请添加一些子选择器,以便只有td
第一个顶级中的顶级 str
获得样式:
.category_table > tbody > tr:first-child > td {
vertical-align: top;
}
回答by Simone
This should do the work:
这应该做的工作:
.category_table tr:first-child td {
vertical-align: top;
}
回答by Vikas Kumar
Below works for first tr
of the table under thead
以下适用于tr
下表中的第一个thead
table thead tr:first-child {
background: #f2f2f2;
}
And this works for the first tr
of thead
and tbody
both:
这适用于第一tr
的thead
和tbody
两个:
table thead tbody tr:first-child {
background: #f2f2f2;
}