首页 > 关于css选择器:nth-of-type的问题

关于css选择器:nth-of-type的问题

请问为什么是:nth-of-type(2)而不是:nth-of-type(1)呢?


因为是 ntf-of-type 的值是匹配第 2 个元素的,可以看 MDN 上 nth-of-child 的解释,是一样的:https://developer.mozilla.org/zh-CN/docs/Web/CSS/:nth-child


注意前面的类.uib-weeks 是从这里开始的,我写了一个demo,你可以参考一下!!

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>test</title>
<link rel="stylesheet" type="text/css"     href="http://apps.bdimg.com/libs/todc-bootstrap/3.1.1-3.2.1/todc-bootstrap.min.css">
<style type="text/css">
*{margin: 0; padding: 0;}
table {margin:20px auto;}
.uib-weeks { #eee; border: 2px solid #ddd;}
.uib-day {padding: 2rem; }
.uib-weeks .uib-day:nth-of-type(2) .btn-default {color: #f00; !important;}
</style>
</head>
<body>
<table cellpadding="0" cellspacing="0">
<tbody>
<tr class="uib-weeks">
<td class="uib-day"><button class="btn btn-default">btn</button></td>
<td class="uib-day"><button class="btn btn-default">btn</button></td>
<td class="uib-day"><button class="btn btn-default">btn</button></td>
<td class="uib-day"><button class="btn btn-default">btn</button></td>
<td class="uib-day"><button class="btn btn-default">btn</button></td>
<td class="uib-day"><button class="btn btn-default">btn</button></td>
<td class="uib-day"><button class="btn btn-default">btn</button></td>
</tbody>
</table>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script type="text/javascript" src="http://apps.bdimg.com/libs/bootstrap/3.3.4/js/bootstrap.min.js"></script>
</body>
</html>

nth-of-type 注意里面的序号是从 1开始的。

【热门文章】
【热门文章】