本文介绍了:nth-of-type(n)不能按预期工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用:nth-of-type(n)
进行选择时,不会返回预期的响应。
When using :nth-of-type(n)
to make a selection it does not return the expected response.
我想用className b
选择第二个< td>
I'm wanting to select the second <td>
element with className b
.
为什么使用选择器 .b:nth-of-type(2)
>
Why when using selector .b:nth-of-type(2)
yield no result?
<div id="foot">
<table id="nav">
<tbody>
<tr valign="top">
<td class="b"><b>Previous</b></td>
<td><b>1</b></td>
<td><a href="#">2</a></td>
<td><a href="#">3</a></td>
<td><a href="#">4</a></td>
<td><a href="#">5</a></td>
<td><a href="#">6</a></td>
<td><a href="#">7</a></td>
<td><a href="#">8</a></td>
<td><a href="#">9</a></td>
<td><a href="#">10</a></td>
<td class="b"><a href="#">Next</a></td>
</tr>
</tbody>
</table>
</div>
条款
Stipulations
-
< td>
的数量可以更改。 - 纯JavaScript / CSS。
- The number of
<td>
elements can change. - pure JavaScript/CSS only.
虽然 .b:nth-last-child(1)
会工作,
这个问题是为了理解为什么 .b:nth-child(2)
不会返回相同的。
Although .b:nth-last-child(1)
would work,
this question is to understand why .b:nth-child(2)
does not return the same.
推荐答案
从 W3C 规格
所以看起来你不能使用类名来选择元素和这个伪类。
So it looks like you can't use class name to select elements along with this pseudo class.
这篇关于:nth-of-type(n)不能按预期工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!