CSS选择器的第n个范围? [英] CSS Selector for nth range?

查看:110
本文介绍了CSS选择器的第n个范围?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何调整以下CSS选择器:

  .myTableRow td:nth-​​child(?){
background-color:#FFFFCC;
}

因此它适用于td列2-4?

 < table> 
< tr class =myTableRow>
< td>列1< / td>
< td>栏2< / td>
< td> column 3< / td>
< td> column 4< / td>
< td>栏5< / td>
< / tr>
< / table>


解决方案

单独:nth-​​child() - 你需要链接至少一个其他这样的伪类。例如,:nth-​​child():nth-​​last-child() code> n + 2 位意味着分别从第二个孩子开始向前和向后计数):

  .myTableRow td:nth-​​child(n + 2):nth-​​last-child(n + 2){
background-color:#FFFFCC;
}

或者,不使用公式, c>:first-child 和:last-child



< .myTableRow td:not(:first-child):not(:last-child){
background-color:#FFFFCC;
}


How can I adapt the CSS selector below:

.myTableRow td:nth-child(?){
background-color: #FFFFCC;
}

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>

解决方案

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;
}

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;
}

这篇关于CSS选择器的第n个范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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