How can I get a specific number child using CSS?(如何使用 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 获得特定数字的孩子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 CSS 获得特定数字的孩子?
基础教程推荐
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
