如何使用 CSS 获得特定数字的孩子? [英] How can I get a specific number child using CSS?

查看:16
本文介绍了如何使用 CSS 获得特定数字的孩子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 table,它的 td 是动态创建的.我知道如何获得第一个和最后一个孩子,但我的问题是:

I have a table whose tds are created dynamically. I know how to get the first and last child but my question is:

有没有办法使用 CSS 获得第二个或第三个孩子?

Is there a way of getting the second or third child using CSS?

推荐答案

对于现代浏览器,第二个 td 使用 td:nth-child(2),并且td:nth-child(3) 用于第三个.请记住,它们会为每一行检索第二个和第三个 td .

For modern browsers, use td:nth-child(2) for the second td, and td:nth-child(3) for the third. Remember that these retrieve the second and third td for every row.

如果您需要兼容 IE 9 之前的版本,请使用兄弟组合符或 JavaScript 按照 Tim 的建议.另请参阅我对 this 的回答相关问题 来解释和说明他的方法.

If you need compatibility with IE older than version 9, use sibling combinators or JavaScript as suggested by Tim. Also see my answer to this related question for an explanation and illustration of his method.

这篇关于如何使用 CSS 获得特定数字的孩子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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