[英]CSS nth-of-type not working as expected
What am I missing out on the functionality of the nth-of-type CSS3 selector? 我在第n个类型CSS3选择器的功能上缺少什么?
Please see this codepen http://codepen.io/tuleby/pen/oqKAG 请参阅此codepen http://codepen.io/tuleby/pen/oqKAG
The desired result is three even rows with 6 divs on each, and thus 6 + 12 + 18 should be red. 期望的结果是三个偶数行,每个行具有6 div,因此6 + 12 + 18应该为红色。 How come this does not work? 为什么这不起作用?
Thanks 谢谢
HTML: HTML:
<div id="staff">
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
<div>9</div>
<div>10</div>
<div>11</div>
<div>12</div>
<div>13</div>
<div>14</div>
<div>15</div>
<div>16</div>
<div>17</div>
<div>18</div>
</div>
CSS: CSS:
#staff {
width:100%;
}
#staff div {
float:left;
width: 14%;
margin: 0 3.2% 20px 0;
background-color: #ccc;
}
#staff div:nth-of-type(6) {
background-color: red;
margin-right: 0;
}
You need to use n
to your nth-of-type like this 您需要使用n
您第n-的型像这样
#staff div:nth-of-type(6n) {
background-color: red;
margin-right: 0;
}
for example nth-of-type(6n+2)
- 6
represents a cycle size, n
is a counter, and 2
are when is beginning 例如nth-of-type(6n+2)
6
代表一个循环大小, n
是一个计数器,而2
是开始时间
根据此处的规范,将:nth-of-type(6)
更改为:nth-of-type(6n)
: http : //www.w3.org/TR/css3-selectors/#nth-of-type-伪 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.