首页 > 解决方案 > Should html header tag only contain info common to all pages

问题描述

My header tag contains an image (logo) which is common to all pages and then page title which is different for each page. Suddenly occurred to me that perhaps only the image should be part of the header tag and title shoud go in the body tag ?

e.g

<header>
    <img srcset="style/songkongheader.png 400w,style/songkongheader-medium.png 200w,style/songkongheader-small.png 100w," sizes="(max-width:800px) 200px,(max-width:600px) 100px,400px" class="mb-2">
    <h2 class="subheading ui-corner-all" title="Undo Fixes">
        <a style="text-decoration: none">
            Undo Fixes
        </a>
    </h2>
</header>

Could someone please clarify

标签: html

解决方案


您现在使用的方式<header>似乎是完全有效和正确的。
根据MDN

<header>元素没有对内容进行分段,因此不会在大纲中引入新的部分。也就是说,一个<header>元素通常旨在包含周围部分的标题(一个 h1-h6 元素),但这不是必需的。

他们提供了一个Page Header例子(你的情况是 100%):

<header>
  <h1>Main Page Title</h1>
  <img src="mdn-logo-sm.png" alt="MDN logo">
</header>

推荐阅读