2

私は何か間違ったことをしていますか?

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.

これは機能せず、最初の にまだ境界線があり<article>ます。別のクラスを作成article.noborderし、最初の記事のようなことをして境界線をなくす必要があります。何か助けていただければ幸いです...cssは私を嫌っています。

4

3 に答える 3

14

最初の が先行する:first-of-typeため、使用する必要があります。h2article

于 2011-09-20T13:52:54.643 に答える
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 に答える
1

H2 はセクションの最初の子であり、最初の記事ではないようです。

于 2011-09-20T13:52:45.190 に答える