- Products -


Software


NEWS


Special



- Knowledge -


Category × Tag



- Like -

公開
作成日:2021/10/24
更新日:2022/3/4

【CSS】セレクタで最後の要素や何番目の要素という指定をする方法

・1番目を指定する方法は、「:first-child」

・最後の要素を指定する方法は、「:last-child」

・任意の要素のみを指定する方法は、「:nth-of-type(n)」

・その他、偶数のみ・奇数のみという指定も可能。

使い方


・クラス指定で画面内には複数要素あるが、1番目だけ別のスタイルを強制する例

.sep_date:nth-of-type(1){
    margin-top: 0px !important;
}


参考


https://coonelnel.net/selector/#toc1


Category



Tag




関連記事


{{tmp.name}}

{{article.category}} {{article.title}}