teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

コード追加

2020/06/16 05:22

投稿

hatena19
hatena19

スコア34367

answer CHANGED
@@ -10,4 +10,15 @@
10
10
  }
11
11
  ```
12
12
 
13
- h2 の後に p要素とか別の要素が続くなら :nth-child では難しいかと。
13
+ h2 の後に p要素とか別の要素が続くなら :nth-child では難しいかと。:nth-of-typea
14
+ を使うといいでしょう。
15
+
16
+ ```css
17
+ h2 {
18
+ background-color: #ad1452;
19
+ }
20
+
21
+ h2:nth-of-type(4n-1), h2:nth-of-type(4n){
22
+ background-color: #2d4084;
23
+ }
24
+ ```