CSS Selector for nth range?(第 n 个范围的 CSS 选择器?)
问题描述
如何调整下面的 CSS 选择器:
How can I adapt the CSS selector below:
.myTableRow td:nth-child(?){
background-color: #FFFFCC;
}
所以它适用于 td 列 2~4?
so it applies to td columns 2~4?
<table>
<tr class="myTableRow">
<td>column 1</td>
<td>column 2</td>
<td>column 3</td>
<td>column 4</td>
<td>column 5</td>
</tr>
</table>
推荐答案
你不能用一个单一的 :nth-child() 来做到这一点——你需要在至少还有一个这样的伪类.例如,:nth-child() 和 :nth-last-child() 的组合(n+2 位表示开始从第二个孩子开始分别向前和向后计数):
You won't be able to do this with a single :nth-child() — you'll need to chain at least one other such pseudo-class. For example, a combination of :nth-child() and :nth-last-child() (the n+2 bit means start counting forward and backward respectively from the 2nd child):
.myTableRow td:nth-child(n+2):nth-last-child(n+2){
background-color: #FFFFCC;
}
或者,不使用公式,只需排除 :first-child 和 :last-child:
Alternatively, instead of making use of a formula, simply exclude :first-child and :last-child:
.myTableRow td:not(:first-child):not(:last-child){
background-color: #FFFFCC;
}
这篇关于第 n 个范围的 CSS 选择器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:第 n 个范围的 CSS 选择器?
基础教程推荐
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
