将样式应用于第一行的单元格 [英] Apply style to cells of first row

查看:110
本文介绍了将样式应用于第一行的单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一张这样的表格:


$ b $这个表格应该很简单,但我无法弄清楚。 b

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

我想让 td 第一个标签 tr 行有 vertical-align 。但不是第二行。

  .category_table td {
vertical-align:top;


解决方案使用 tr:first-child 取第一个 tr

  .category_table tr:first-child td {
vertical-align:top;





$ b

如果你有嵌套表,并且你不想将样式应用到在内部行中添加一些子选择器,以便仅在第一个顶级 tr 中的顶级 td 中获取get样式:

.category_table> tbody> tr:第一个孩子> td {
vertical-align:top;
}


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.

.category_table td{
    vertical-align:top;
}

解决方案

Use tr:first-child to take the first 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 tds in the first top-level tr get the styles:

.category_table > tbody > tr:first-child > td {
    vertical-align: top;
}

这篇关于将样式应用于第一行的单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆