Home  >  Article  >  Web Front-end  >  关于CSS3 :nth-child() 选择器_html/css_WEB-ITnose

关于CSS3 :nth-child() 选择器_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:57:24932browse

一个有很多个小方块的页面,大方块的class为big,小方块的class为small,用css3选择器这么写:

.small:nth-child(even){margin-right:0;}


设置第偶数个小方块的margin-right为0,但是第三个小方块的margin-right却等于0了,怎么回事呢?

demo:http://guusoft.com/test/


回复讨论(解决方案)

通过其他网友的指点,明白了从父元素中选择第奇数或者偶数个子元素并不会特指某种类型(.small),而是将所有子元素都计算进去的。
所以最后的解决方法是:

$(".small:odd").addClass("last");

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn