高品質のセマンティック HTML5 を作成しようとしています。
次の 2 つのオプションのうち、意味的に優れているのはどれですか。
オプション1:
ID を使用してスパンを選択し、スタイルを定義します。
%body
%header#global-header
%h1
My Startup Name
%h2
Home of the best offers in the Motor City
%section#offers
%h1
Today's Offers
%h2
Here are the current offers for your city:
%article.offer
%header.offer-header
%span.restaurant-name
Some Burger Joint
%span.offer-title
80% off a burger
%section.price-details
%ul
%li.original-price
%p
Original Price
%p
$30
%li.offer-price
%p
Price
%p
$10
%section.offer-description
%p
Some burger joint is the most popular burger joint in the Motor City. Buy a big burger or a bunch of belly bombers.
%article.offer
...another offer...
このオプションの下で、SASS で次のようなレストラン名とオファータイトルを選択してスタイルを設定します。
body {
h1 { font-size: 3em; }
h2 { font-size: 2em; }
article {
.restaurant-name { font-size: 1.25em; }
.offer-title { font-size: 1.5em; }
}
}
オプション 2:
スタイルを範囲内にスコープし、クラスまたは ID でタグを付けて、h1 から h6 を使用します。
%body
%header#global-header
%h1
My Startup Name
%h2
Home of the best offers in the Motor City
%section#offers
%h1
Today's Offers
%p
Here are the current offers for your city:
%article.offer
%header.offer-header
%h2.restaurant-name
Some Burger Joint
%h3.offer-title
80% off a burger
%section.price-details
%ul
%li.original-price
%h4
Original Price
%h4
$30
%li.offer-price
%h4
Price
%h4
$10
%section.offer-description
%p
Some burger joint is the most popular burger joint in the Motor City. Buy a big burger or a bunch of belly bombers.
%article.offer
...another offer...
このオプションの下で、SASS で次のようなレストラン名とオファータイトルを選択してスタイルを設定します。
body {
h1 { font-size: 3em; }
h2 { font-size: 2em; }
article {
%h1 { font-size: 1.25em; }
%h2 { font-size: 1.5em; }
}
}
オプション 1 では、ID を使用してスタイルを定義し、要素を選択してスタイルを設定します。オプション 2 では、h1 から h6 のスタイルを再び使用してスタイルを定義していますが、これらのスタイルは文書全体ではなく記事に適用されます。囲んでいるページには、タイトル用の h1 タグと h2 タグがあり、全体のサブタイトルがあります。
h1 から h6 タグは、サイト全体で 1 つの方法でのみ使用されることになっていますか? それとも、サイトの主要部分内で h1 から h6 の範囲を指定しても問題ないでしょうか? たとえば、上記のサイトでは、ID オファーのあるセクションがサイトの主要部分になり、同様に非常に重要な他のセクションがあります。
オプション 1 の方が説明的であるため、保守しやすいという印象を受けます。ただし、同じ保守性を実現するために、オプション 2 で引き続き ID を使用することを妨げるものは何もありません。オプション 2 は、コードをスリムに保ち、html ファイルと css ファイルを小さく保つという点で優れていると思います。
特に両方でIDを自由に使用している場合、実際に一方が他方よりも意味的に優れているかどうかはわかりません。それでも、私のユースケースでは、h1-h6 とスパンのどちらが意味的に優れているかという問題が残ります。
それがすべて理にかなっていることを願っています。明確にする必要がある場合はお知らせください。