简体   繁体   English

如何使用CSS在表格中为第n个td设置样式

[英]How to set style for n-th td in a table using css

I have a table with 10 columns . 我有一张有10列的桌子。 How I can write css classes that set style for all TD s in 2 or 7 position ? 如何编写在2或7位设置所有TD样式的css类?

Something like: 就像是:

tr td:nth-child(2), tr td:nth-child(7) {
    /* style here */
}

It's not supported in IE8 . IE8不支持它。 But here's a very nice polyfill: ie9.js . 但这是一个非常不错的polyfillie9.js

Alternatives: 备择方案:

  1. Use jQuery 使用jQuery
  2. Add a custom class to each 2nd and 7th td 将自定义类添加到第二个和第七个td

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM