有没有办法让表格中的某些列居中? [英] Is there any way to center certain columns in table?

查看:122
本文介绍了有没有办法让表格中的某些列居中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我广泛使用css格式化并为表定义类,包括thead,tbody,tfoot的子类以及tr,th,td ....的另一个子类级。

I'm widely using css formatting and define class for table with subclasses for thead, tbody, tfoot and another level of subclasses for tr, th, td....

在某些情况下,我想让表格的整列具有某种风格的类......但不知道该怎么做。

In some cases I want to make whole column for table to have class with certain style... but don't know how to do that.

是否有任何方式(使用HTML5,css3,其他什么?)使tbody的某一列中的所有单元格具有相同的类?

Is there any way (using HTML5, css3, anything else?) to make all cells in certain column of tbody to have the same class?

我可以明确地(手动)指定类,但我想避免这种重复。

I can specify class explicitly (manually), but I would like to avoid that kind of duplication.

欢迎任何想法。

PS可能我不应该为此烦恼,只是为每个单元格明确指定类?

P.S. Probably I should not bother myself with that and just explicitly specify class for each cell?

推荐答案

您可以使用nth-child css伪选择器来定位表格的中间列。

You can use the nth-child css pseudo-selector to target the middle column of your table.

示例:

#myTable tr td:nth-child(3) {
  text-align: center;
}

这将连续瞄准第3列,只需相应调整X.对于每个第n个孩子,也可以使用n作为变量。查看 http://css-tricks.com/how-nth-child-works/ 以获得全面的示例。

This would target the 3rd column in a row, just adjust your X accordingly. It is also possible to use "n" as a variable for every nth child. Check out http://css-tricks.com/how-nth-child-works/ for a comprehensive example.

这篇关于有没有办法让表格中的某些列居中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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