CSS各种坑

502 阅读1分钟

1号坑:nth-of-type

nth- 不会尊重类,因此在选择器中使用它是没有意义的, nth-of-type() {}未应用于类,仅作用于选择器

<div class='test'>1</div><div class='test'>2</div><div class='test'>3</div><div class='test'>4</div><div class='test'>5</div><div class='test'>6</div>

错误用法:

.test:nth-of-type(2){

color:#000;} 

因为用类名来选  这样不会生效!

正确的用法是

div:nth-of-type(2){color:#000;}