简体   繁体   English

CSS nth-child错过了元素

[英]CSS nth-child misses element

Seems like css nth-child missed its target, any thoughts? 好像css nth-child错过了它的目标,任何想法?

jsFiddle source jsFiddle来源

HTML: HTML:

<a href="#">red</a>
<br />
<a href="#">none</a>
<br />
<a href="#">gray</a>

CSS: CSS:

a:nth-child(1) {
    color:red;
}
a:nth-child(3) {
    color:gray;
}

Use nth-of-type() instead of nth-child() , it will work perfectly if you are removed the <br/> tag , because as @FritsvanCampen comment it counts as a child 使用nth-of-type()而不是nth-child()它会很好地工作,如果你删除<br/>标签,因为@FritsvanCampen评论它算作一个孩子

a:nth-of-type(1) {
    color:red;
}
a:nth-of-type(3) {
    color:gray;
}

for better understanding refer : http://css-tricks.com/the-difference-between-nth-child-and-nth-of-type/ 为了更好地理解,请参考: http//css-tricks.com/the-difference-between-nth-child-and-nth-of-type/

Fiddle 小提琴

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM