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

查看:88
本文介绍了如何使用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.

如果您需要与版本9之前的IE兼容,请使用同级组合器或JavaScript 此问题的回答相关问题以对其方法进行解释和说明.

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天全站免登陆