문제

How do I semanticly markup the headers in the article as presented in the picture below? I often run into this problem; where I have a header that is visually first, but is a subheading, intro header or less important then the main header. I could put it after the main header and move it above with CSS, but that isn't always a ideal solution.

Another question: is there any special way to markup lead paragraphs?

headermarkup Not allowed?

<article>
<h2>New prodcut</h2>
<h1>Launching our new x-series</h1>
<p class="lead">Lorem ipsum dolor sit amet...</p>
<p>Integer varius, turpis sit amet accumsan...</p>
...
</article>

도움이 되었습니까?

해결책

Don’t use a heading element (h1-h6) for the subheading. This was once possible with the hgroup element, but it got removed.

Now the HTML5 spec has a section about Subheadings, subtitles, alternative titles and taglines. Use a p element for the subheading, and group both, the heading and the subheading in a header element:

<article>
  <header>
    <p>New product</p>
    <h1>Launching our new X-series</h1>
  </header>
</article>

If you think the lead paragraph should also be part of the header (instead of the main content), you can put it in the header, too.

다른 팁

The HTML Standard as of 2023 recommends the use of the <hgroup> element for subheading, alternative titles, and taglines:

<article>
  <hgroup>
    <p>New product</p>
    <h1>Launching our new x-series</h1>
    <p>Lorem ipsum dolor sit amet...</p>
  </hgroup>
  <p>Integer varius, turpis sit amet accumsan...</p>
  ...
</article>

Permitted content:

  1. Zero or more <p> elements,
  2. followed by one <h1> , <h2>, <h3>, <h4>, <h5>, or <h6> element,
  3. followed by zero or more <p> elements.

See: 4.3.7 The hgroup element

While not explicitly mentioned, I would consider the lead paragraph to be content related to a heading and would thus place it in the <hgroup> as well.

Setting classes like <p class="lead"> is not required thanks to the <hgroup> element, which lets you target the subheading and the lead paragraph in CSS easily:

hgroup > p:first-child { /* or  hgroup p:has(+ h1)  for the <p> before <h1> */
  font-size: 16pt;
}

hgroup h1 + p {
  font-size: 14pt;
  font-style: italic;
}

While what you are doing is syntactically allowed, I think it will case confusion for low vision users.

How about doing something like this:

<div class="newproduct>New Product</div>
<div class="articletitle">Launching our new x-series</div>
Lorem ipsum....

If you want to use some newer HTML, I would recommend you look into article and section tags.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top