How can I get a specific number child using CSS?(如何使用 CSS 获得特定数字的孩子?)
问题描述
我有一个 table
,它的 td
是动态创建的.我知道如何获得第一个和最后一个孩子,但我的问题是:
I have a table
whose td
s 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 获得特定数字的孩子?


- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- 400或500级别的HTTP响应 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- Flexslider 箭头未正确显示 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01