1. 程式人生 > 其它 >8.9前端之Html語義

8.9前端之Html語義

8.9前端之Html語義

什麼是語義元素

  • 語義元素清楚地向瀏覽器和開發者描述其意義

舉例:

非語義元素:<div><span> ---> 特點:無法提供關於其內容的資訊。

語義元素:<form>,<table>,<img>--->特點:清晰地定義其內容

Html5中新的語義元素

許多網站包含了指示導航、頁首以及頁尾的 HTML 程式碼,例如這些:<div id="nav"> <div class="header"> <div id="footer">

標籤描述
<article>
定義文章。規定獨立的自包含內容。文件有其自身的意義,並且可以獨立於網站其他內容進行閱讀。
<aside> 定義頁面內容以外的內容。比如側欄。aside 內容應該與周圍內容相關。
<details> 定義使用者能夠檢視或隱藏的額外細節。
<figcaption> 定義 <figure> 元素的標題。
<figure> 規定自包含內容,比如圖示、圖表、照片、程式碼清單等。圖片和標題能夠被組合在 <figure>元素中
<footer> 定義文件或節的頁尾。提供有關其包含元素的資訊。包含文件的作者、版權資訊、使用條款連結、聯絡資訊等等。
<header> 規定文件或節的頁首。被用作介紹性內容的容器。一個文件中可以有多個 <header> 元素。
<main> 規定文件的主內容。
<mark> 定義重要的或強調的文字。
<nav> 定義導航連結。是一個集合。旨在定義大型的導航連結塊,並非文件中所有連結都應該位於<nav>元素中!
<section> 定義文件中的節。“節(section)是有主題的內容組,通常具有標題。可以將網站首頁劃分為簡介、內容、聯絡資訊等節
<summary> 定義<details>
元素的可見標題。
<time> 定義日期/時間。

可以簡單的理解為:每個語義元素下必須接內容。

<section>
        <section contenteditable="false">
<h1>Semantic Elements</h1>
<p contenteditable="true" style="font-family: '微軟雅黑'; color: saddlebrown; font-size: medium;">This is a content about Semantic Elements</p>
</section>
<section contenteditable="false">
<h1>Content</h1>
<p contenteditable="true" style="font-family: '微軟雅黑'; color: darkmagenta; font-size: large;">Input Something</p>
</section>
<article>
        <article contenteditable="false" style="font-family: '微軟雅黑'; color: black; font-size: large;">
<h1>What can you do</h1>
<p contenteditable="false" style="font-family: '微軟雅黑'; color: royalblue; font-size: medium;">It is a content</p>
</article>

<section>元素和<article>元素的區別

  • <article>元素定義完整的相關元素自包含塊。<section>元素被定義為相關元素塊。

  • 不能夠使用該定義來決定如何巢狀元素

  • <section>可包含<article>也可包含<section>

  • <article>可包含<article>也可包含<sections>

<header>

<table>標籤的<thead>標籤型別,定義頁首

        <article contenteditable="false" style="font-family: '微軟雅黑'; color: blanchedalmond;">
<header contenteditable="false" style="font-family: '微軟雅黑'; color: darkblue; font-size: larger;">
<h1>Title of the article</h1>
<p contenteditable="false" style="font-family: '微軟雅黑'; color: black; font-size: medium;">What is the title of the article</p>
</header>
<p contenteditable="true" style="font-family: '微軟雅黑'; color: black; font-size: initial;">Input your answer</p>
</article>
<footer>
            <footer contenteditable="false" style="font-family: '微軟雅黑'; color: darkcyan; font-size: inherit;">
<p contenteditable="false">Information from:<a href="PracticeList.html">[email protected]</a>.</p>
</footer>
<aside>
            <p contenteditable="false" style="font-family: '微軟雅黑';">This is a content</p>
<aside contenteditable="false" style="font-family: '微軟雅黑'; color: red; font-size: inherit;">
<ul contenteditable="false" style="font-family: '微軟雅黑'; color: hotpink;">
<li>Html</li>
<li>Css</li>
<li>JavaScript</li>
</ul>
</aside>
<figure><img><figcaption>
  • <figure>內放<img><figcaption>

        <p contenteditable="false">This is a content about picture</p>
<figure>
<figcaption contenteditable="false" style="font-family: '微軟雅黑'; color: red; text-align: left;">皮卡丘,大大大</figcaption>
<img src="../Picture/Big.gif" alt="This is a Picture" width="304" height="228" />
</figure>

It's a lonely road!!!