开发者

pseudoclass :first-child not working

Am I doing something wrong?

css/sass:

#section
  article
   border-top: 1px solid black
   &:first-child
     border: none !important

html/haml:

#section
  %h2 title
   %article
    stuff here. There is still a top border here despite first-child style.
   %article
    stuff here.
   %article
    stuff here.

This doesn't work, and there is still a border on the first <article>. I have to make another class and do something like article.noborder on the fir开发者_开发知识库st article to get no border. Any help would be appreciated...css hates me.


You have to use :first-of-type because of the h2 preceding the first article.


Seems to me that the H2 is the first child of the section, not the first article.


section article:first-child{
  border:none;
}

section article:nth-child(2){
  border:2px solid yellow;
}

I meet this issue before, try to remember that don't use different way to call the same elements.

If you use body section article { border:2px solid yellow} will overlap the
section article:first-child{...} because the former one is more specific.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜