2

难道我做错了什么?

CSS/萨斯:

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

html/哈姆尔:

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

这不起作用,并且第一个<article>. article.noborder我必须再上一堂课,并在第一篇文章中做类似的事情才能获得无边界。任何帮助将不胜感激......css讨厌我。

4

3 回答 3

14

你必须使用:first-of-type因为h2前面的第一个article.

于 2011-09-20T13:52:54.643 回答
1

在我看来,H2 是该部分的第一个孩子,而不是第一篇文章。

于 2011-09-20T13:52:45.190 回答
1
section article:first-child{
  border:none;
}

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

我以前遇到过这个问题,尽量记住不要使用不同的方式来调用相同的元素。

如果您使用body section article { border:2px solid yellow}将重叠,
section article:first-child{...}因为前者更具体。

于 2011-09-21T04:16:53.890 回答