When do I put

-

inside an
element

2019-08-12 13:58发布

When do I put headings inside a header element? I can't understand it, sometimes it seems to me that each heading has to be between header tags.

Let's take this sidebar as example :
enter image description here

How to code it?

<aside>
  <header>
    <h1>How to format</h1>
  </header>
</aside>

or

<aside>
  <h1>How to format</h1>
</aside>

3条回答
时光不老,我们不散
2楼-- · 2019-08-12 14:21

<header> give us some great added semantic value in order to describe the head of a section. You can use multiple headers in a web page, each of which will then become the <header> for that section of the document. So, using a <header> depends on the complexity of the section. The more complex it is, the more necessary the header element becomes. a <header> typically contains at least (but not restricted to) one heading tag (<h1> – <h6>).

hope it helps

查看更多
狗以群分
3楼-- · 2019-08-12 14:32

See the specification of the header element:

A header element is intended to usually contain the section's heading (an h1–h6 element), but this is not required. The header element can also be used to wrap a section's table of contents, a search form, or any relevant logos.

So you can have many header elements in a page (it's not limited to the top of the page), and you can use it around headings, but it's optional. This means both of your examples are correct.

查看更多
The star\"
4楼-- · 2019-08-12 14:42

The header tag is for what displays at the top of the page of the page-what is sometimes called the banner. So put your h1-h6 tags in it when they are in the banner of your page.

Tags like header and footer are basically just div's renamed for organizational sanity. In the future search engines and browsers may look for header and footer tags to help them process and display information better. For now, it lets you avoid staring at a bunch of div tags.

<html>
<head>
</head>
<body>
    <header> Web page Banner</header>
    <div>Content</div>
    <footer>Web page bottom </footer> 
<body>
</html>

Instead of this...

<html>
<head>
</head>
<body>
    <div> Web page Banner</div>
    <div>Content</div>
    <div>Web page bottom </div> 
<body>
</html>
查看更多
登录 后发表回答