0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【CSS/HTML】class属性とid属性について

Posted at

class属性とid属性とは

class属性とid属性は、特定の要素に対して指定を行いたい場合、HTMLのタグに名前を付けるために使用される。CSSでは、特定の要素をセレクタで指定するためにidclassで付けられた名前を用いる。
classとidの違い
class:1ページの中に何度も同じ値(名前)を使うことができる。(重複可)
id:1ページの中に同じ値(名前)一度しか使うことができない。(重複不可)

また、idclassではCSSでのスタイルが適用される優先順位が決まっており、classよりもidのスタイルが優先される

CSSでのセレクタ指定方法

CSSにおいてidやclassで名前を付けた要素をセレクタに指定する場合は、idは#、classは.を付けて以下のように記述できる。
しかし、スタイルシートではidセレクタを使用すべきではない

/* idセレクタの場合 */
# <id名>{
    <プロパティ>: <値>;
}
/* classの場合 */
.<class名>{
    <プロパティ>: <値>;
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?