<main>: 主元素
試一試
文件中不能包含多個 <main> 元素,且不應指定 hidden 屬性。
屬性
此元素僅包含 全域性屬性。
使用說明
無障礙性
地標
跳過導航
跳過導航,也稱為“skipnav”,是一種技術,允許輔助技術使用者快速跳過大量重複的內容(主要導航、資訊橫幅等)。 這讓使用者可以更快地訪問頁面的主要內容。
將 id 屬性新增到 <main> 元素,可以使其成為跳過導航連結的目標。
html
<body>
<a href="#main-content">Skip to main content</a>
<!-- navigation and header content -->
<main id="main-content">
<!-- main page content -->
</main>
</body>
閱讀模式
示例
html
<!-- other content -->
<main>
<h1>Apples</h1>
<p>The apple is the pomaceous fruit of the apple tree.</p>
<article>
<h2>Red Delicious</h2>
<p>
These bright red apples are the most common found in many supermarkets.
</p>
<p>…</p>
<p>…</p>
</article>
<article>
<h2>Granny Smith</h2>
<p>These juicy, green apples make a great filling for apple pies.</p>
<p>…</p>
<p>…</p>
</article>
</main>
<!-- other content -->
結果
技術概述
| 內容類別 | 流內容,可感知的內容。 |
|---|---|
| 允許的內容 | 流內容. |
| 標籤省略 | 無; 開始和結束標籤都是強制性的。 |
| 允許的父級 | 在預期 流內容 的地方,但前提是它是一個 分層正確的 main 元素。 |
| 隱式 ARIA 角色 | main |
| 允許的 ARIA 角色 | 不允許使用 role |
| DOM 介面 | HTMLElement |
規範
| 規範 |
|---|
| HTML 標準 # the-main-element |
瀏覽器相容性
BCD 表格僅在瀏覽器中載入