html5語義化標記元素_語義HTML5元素介紹

html5語義化標記元素

Semantic HTML elements are those that clearly describe their meaning in a human- and machine-readable way.

語義HTML元素是以人類和機器可讀的方式清楚地描述其含義的元素。

Elements such as <header>, <footer> and <article> are all considered semantic because they accurately describe the purpose of the element and the type of content that is inside them.

諸如<header><footer><article>元素都被認為是語義的,因為它們準確地描述了元素的用途以及它們內部內容的類型。

什么是語義元素? (What are Semantic Elements?)

HTML was originally created as a markup language to describe documents on the early internet. As the internet grew and was adopted by more people, its needs changed.

HTML最初是作為一種標記語言創建的,用于描述早期Internet上的文檔。 隨著互聯網的發展和越來越多的人采用互聯網,其需求發生了變化。

Where the internet was originally intended for sharing scientific documents, now people wanted to share other things as well. Very quickly, people started wanting to make the web look nicer.

互聯網最初旨在??共享科學文檔,而現在人們也希望共享其他內容。 很快,人們開始希望使網絡看起來更好。

Because the web was not initially built to be designed, programmers used different hacks to get things laid out in different ways. Rather than using the <table></table> to describe information using a table, programmers would use them to position other elements on a page.

因為最初并不是為設計網絡而設計的,所以程序員使用不同的技巧來以不同的方式布置事物。 程序員不是使用<table></table>來使用<table></table>來描述信息,而是會使用它們在頁面上放置其他元素。

As the use of visually designed layouts progressed, programmers started to use a generic “non-semantic” tag like <div>. They would often give these elements a class or id attribute to describe their purpose. For example, instead of <header> this was often written as <div class="header">.

隨著視覺設計布局的使用的發展,程序員開始使用通用的“非語義”標記,例如<div> 。 他們通常會給這些元素一個classid屬性來描述它們的目的。 例如,它通常代替<header>編寫為<div class="header">

As HTML5 is still relatively new, this use of non-semantic elements is still very common on websites today.

由于HTML5仍然是相對較新的,因此在當今的網站上,非語義元素的這種使用仍然非常普遍。

新語義元素列表 (List of new semantic elements)

The semantic elements added in HTML5 are:

HTML5中添加的語義元素是:

  • <article>

    <article>

  • <aside>

    <aside>

  • <details>

    <details>

  • <figcaption>

    <figcaption>

  • <figure>

    <figure>

  • <footer>

    <footer>

  • <header>

    <header>

  • <main>

    <main>

  • <mark>

    <mark>

  • <nav>

    <nav>

  • <section>

    <section>

  • <summary>

    <summary>

  • <time>

    <time>

Elements such as <header>, <nav>, <section>, <article>, <aside>, and <footer> act more or less like <div> elements. They group other elements together into page sections. However where a <div> tag could contain any type of information, it is easy to identify what sort of information would go in a semantic <header> region.

諸如<header><nav><section><article><aside><footer>類的元素或多或少類似于<div>元素。 他們將其他元素組合到頁面部分中。 但是,在<div>標記可以包含任何類型的信息的地方,很容易確定語義<header>區域中將包含哪種信息。

An example of semantic element layout by w3schools

w3schools的語義元素布局示例

為什么要使用語義元素? (Why use semantic elements?)

To look at the benefits of semantic elements, here are two pieces of HTML code. This first block of code uses semantic elements:

為了查看語義元素的好處,這里有兩段HTML代碼。 第一部分代碼使用語義元素:

<header></header>
<section><article><figure><img><figcaption></figcaption></figure></article>
</section>
<footer></footer>

Whilst this second block of code uses non-semantic elements:

盡管第二個代碼塊使用非語義元素:

<div id="header"></div>
<div class="section"><div class="article"><div class="figure"><img><div class="figcaption"></div></div></div>
</div>
<div id="footer"></div>

First, it is much easier to read. This is probably the first thing you will notice when looking at the first block of code using semantic elements. This is a small example, but as a programmer you can be reading through hundreds or thousands of lines of code. The easier it is to read and understand that code, the easier it makes your job.

首先,它更容易閱讀 。 當使用語義元素查看第一段代碼時,這可能是您會注意到的第一件事。 這是一個小例子,但是作為程序員,您可以閱讀成百上千的代碼行。 越容易閱讀和理解該代碼,就越容易完成工作。

It has greater accessibility. You are not the only one that finds semantic elements easier to understand. Search engines and assistive technologies (like screen readers for users with a sight impairment) are also able to better understand the context and content of your website, meaning a better experience for your users.

它具有更大的可訪問性 。 您不是唯一發現語義元素更容易理解的人。 搜索引擎和輔助技術(例如視力障礙用戶的屏幕閱讀器)也可以更好地了解您網站的上下文和內容,從而為用戶帶來更好的體驗。

Overall, semantic elements also lead to more consistent code. When creating a header using non-semantic elements, different programmers might write this as <div class="header">, <div id="header">, <div class="head">, or simply <div>. There are so many ways that you can create a header element, and they all depend on the personal preference of the programmer. By creating a standard semantic element, it makes it easier for everyone.

總體而言,語義元素還會導致代碼更加一致 。 使用非語義元素創建標頭時,不同的程序員可能將其寫為<div class="header"><div id="header"><div class="head">或簡稱為<div> 。 創建標題元素的方法有很多,它們都取決于程序員的個人喜好。 通過創建標準語義元素,它使每個人都更容易。

Since October 2014, HTML4 got upgraded to HTML5, along with some new “semantic” elements. To this day, some of us might still be confused as to why so many different elements that doesn’t seem to show any major changes.

自2014年10月起,HTML4和一些新的“語義”元素已升級為HTML5。 時至今日,我們中的某些人可能仍對為什么這么多不同的元素似乎沒有顯示出任何重大變化感到困惑。

<section><article> (<section> and <article>)

“What’s the difference?”, you may ask. Both these elements are used for sectioning a content, and yes, they can definitely be used interchangeably. It’s a matter of in which situation. HTML4 offered only one type of container element, which is <div>. While this is still used in HTML5, HTML5 provided us with <section> and <article> in a way to replace <div>.

您可能會問:“有什么區別?”。 這兩個元素都用于分割內容,是的,它們可以互換使用。 這取決于哪種情況。 HTML4僅提供一種容器元素,即<div> 。 盡管在HTML5中仍使用此功能,但HTML5為我們提供了<section><article>來代替<div>

The <section> and <article> elements are conceptually similar and interchangeable. To decide which of these you should choose, take note of the following:

<section><article>元素在概念上相似并且可以互換。 要決定應選擇哪種方式,請注意以下幾點:

  1. An article is intended to be independently distributable or reusable.

    文章旨在獨立分發或可重復使用。
  2. A section is a thematic grouping of content.

    一節是內容的主題分組。
<section><p>Top Stories</p><section><p>News</p><article>Story 1</article><article>Story 2</article><article>Story 3</article></section><section><p>Sport</p><article>Story 1</article><article>Story 2</article><article>Story 3</article></section>
</section>

<header><hgroup> (<header> and <hgroup>)

The <header> element is generally found at the top of a document, a section, or an article and usually contains the main heading and some navigation and search tools.

<header>元素通常位于文檔,節或文章的頂部,通常包含主要標題以及一些導航和搜索工具。

<header><h1>Company A</h1><ul><li><a href="/home">Home</a></li><li><a href="/about">About</a></li><li><a href="/contact">Contact us</a></li></ul><form target="/search"><input name="q" type="search" /><input type="submit" /></form>
</header>

The <hgroup> element should be used where you want a main heading with one or more subheadings.

<hgroup>元素應用于需要一個或多個子標題的主標題的地方。

<hgroup><h1>Heading 1</h1><h2>Subheading 1</h2><h2>Subheading 2</h2>
</hgroup>

REMEMBER, that the <header> element can contain any content, but the <hgroup> element can only contain other headers, that is <h1> to <h6> and including <hgroup>.

請記住, <header>元素可以包含任何內容,但是<hgroup>元素只能包含其他標題,即<h1><h6>并包括<hgroup>

<aside> (<aside>)

The <aside> element is intended for content that is not part of the flow of the text in which it appears, however still related in some way. This of <aside> as a sidebar to your main content.

<aside>元素用于不屬于其出現的文本流的內容,但仍以某種方式相關。 <aside>作為主要內容的側邊欄。

<aside><p>This is a sidebar, for example a terminology definition or a short background to a historical figure.</p>
</aside>

Before HTML5, our menus were created with <ul>’s and <li>’s. Now, together with these, we can separate our menu items with a <nav>, for navigation between your pages. You can have any number of <nav> elements on a page, for example, its common to have global navigation across the top (in the <header>) and local navigation in a sidebar (in an <aside> element).

在HTML5之前,我們的菜單是使用<ul><li>的。 現在,連同這些,我們可以使用<nav>分隔菜單項,以在頁面之間進行導航。 您可以在頁面上具有任意數量的<nav>元素,例如,在頂部進行全局導航(在<header> )和在側欄中進行局部導航(在<aside>元素中)是常見的做法。

<nav><ul><li><a href="/home">Home</a></li><li><a href="/about">About</a></li><li><a href="/contact">Contact us</a></li></ul>
</nav>

If there is a <header> there must be a <footer>. A <footer> is generally found at the bottom of a document, a section, or an article. Just like the <header> the content is generally metainformation, such as author details, legal information, and/or links to related information. It is also valid to include <section> elements within a footer.

如果有一個<header>則必須有一個<footer> 。 通常在文檔,節或文章的底部找到<footer> 。 就像<header> ,內容通常是元信息,例如作者詳細信息,法律信息和/或相關信息的鏈接。 在頁腳中包含<section>元素也是有效的。

<footer>&copy;Company A</footer>

<small> (<small>)

The <small> element often appears within a <footer> or <aside> element which would usually contain copyright information or legal disclaimers, and other such fine print. However, this is not intended to make the text smaller. It is just describing its content, not prescribing presentation.

<small>元素通常出現在<footer><aside>元素內,該元素通常包含版權信息或法律免責聲明以及其他此類精美文字。 但是,這并不是要使文本變小。 它僅是描述其內容,而不是規定演示。

<footer><small>&copy;Company A</small> Date</footer>

<time> (<time>)

The <time> element allows an unambiguous ISO 8601 date to be attached to a human-readable version of that date.

<time>元素允許將明確的ISO 8601日期附加到該日期的人類可讀版本。

<time datetime="2017-10-31T11:21:00+02:00">Tuesday, 31 October 2017</time>

Why bother with <time>? While humans can read time that can disambiguate through context in the normal way, the computers can read the ISO 8601 date and see the date, time, and the time zone.

為什么要困擾<time> ? 雖然人類可以正常方式讀取可以通過上下文進行歧義的時間,但計算機可以讀取ISO 8601日期并查看日期,時間和時區。

<figure><figcaption> (<figure> and <figcaption>)

<figure> is for wrapping your image content around it, and <figcaption> is to caption your image.

<figure>用于將圖像內容包裝在其周圍,而<figcaption>用于為圖像添加標題。

<figure><img src="https://en.wikipedia.org/wiki/File:Shadow_of_Mordor_cover_art.jpg" alt="Shadow of Mordor" /><figcaption>Cover art for Middle-earth: Shadow of Mordor</figcaption>
</figure>

詳細了解新HTML5元素: (Learn more about the new HTML5 elements:)

  • w3schools provides simple and clear descriptions of many of the news elements and how/where they should be used.

    w3schools提供了許多新聞元素及其使用方式/位置的簡單明了描述。

  • MDN also provides a great reference for all HTML elements and goes deeper into each.

    MDN還為所有HTML元素提供了很好的參考,并且對每個元素都有更深入的介紹。

翻譯自: https://www.freecodecamp.org/news/semantic-html5-elements/

html5語義化標記元素

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/390844.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/390844.shtml
英文地址,請注明出處:http://en.pswp.cn/news/390844.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

重學TCP協議(12)SO_REUSEADDR、SO_REUSEPORT、SO_LINGER

1. SO_REUSEADDR 假如服務端出現故障&#xff0c;主動斷開連接以后&#xff0c;需要等 2 個 MSL 以后才最終釋放這個連接&#xff0c;而服務重啟以后要綁定同一個端口&#xff0c;默認情況下&#xff0c;操作系統的實現都會阻止新的監聽套接字綁定到這個端口上。啟用 SO_REUSE…

殘疾科學家_數據科學與殘疾:通過創新加強護理

殘疾科學家Could the time it takes for you to water your houseplants say something about your health? Or might the amount you’re moving around your neighborhood reflect your mental health status?您給植物澆水所需的時間能否說明您的健康狀況&#xff1f; 還是…

POJ 3660 Cow Contest [Floyd]

POJ - 3660 Cow Contest http://poj.org/problem?id3660 N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a programming contest. As we all know, some cows code better than others. Each cow has a certain constant skill rating that is un…

Linux 網絡相關命令

1. telnet 1.1 檢查端口是否打開 執行 telnet www.baidu.com 80&#xff0c;粘貼下面的文本&#xff08;注意總共有四行&#xff0c;最后兩行為兩個空行&#xff09; telnet [domainname or ip] [port]例如&#xff1a; telnet www.baidu.com 80 如果這個網絡連接可達&…

JSON.parseObject(String str)與JSONObject.parseObject(String str)的區別

一、首先來說說fastjson fastjson 是一個性能很好的 Java 語言實現的 JSON 解析器和生成器&#xff0c;來自阿里巴巴的工程師開發。其主要特點是&#xff1a; ① 快速&#xff1a;fastjson采用獨創的算法&#xff0c;將parse的速度提升到極致&#xff0c;超過所有基于Java的jso…

jQuery Ajax POST方法

Sends an asynchronous http POST request to load data from the server. Its general form is:發送異步http POST請求以從服務器加載數據。 其一般形式為&#xff1a; jQuery.post( url [, data ] [, success ] [, dataType ] )url : is the only mandatory parameter. This…

spss23出現數據消失_改善23億人口健康數據的可視化

spss23出現數據消失District Health Information Software, or DHIS2, is one of the most important sources of health data in low- and middle-income countries (LMICs). Used by 72 different LMIC governments, DHIS2 is a web-based open-source platform that is used…

01-hibernate注解:類級別注解,@Entity,@Table,@Embeddable

Entity Entity:映射實體類 Entity(name"tableName") name:可選&#xff0c;對應數據庫中一個表&#xff0c;若表名與實體類名相同&#xff0c;則可以省略。 注意&#xff1a;使用Entity時候必須指定實體類的主鍵屬性。 第一步&#xff1a;建立實體類&#xff1a; 分別…

leetcode 1707. 與數組中元素的最大異或值

題目 給你一個由非負整數組成的數組 nums 。另有一個查詢數組 queries &#xff0c;其中 queries[i] [xi, mi] 。 第 i 個查詢的答案是 xi 和任何 nums 數組中不超過 mi 的元素按位異或&#xff08;XOR&#xff09;得到的最大值。換句話說&#xff0c;答案是 max(nums[j] XO…

MySQL基礎入門學習【2】數據類型

數據類型&#xff1a;指列、存儲過程參數、表達式和局部變量的數據特征&#xff0c;它決定了數據的存儲格式&#xff0c;代表了不同的信息類型 &#xff08;1&#xff09; 整型(按存儲范圍分類)&#xff1a;TINYINT&#xff08;1字節&#xff09; SAMLLINT&#xff08;2字節&am…

昆西·拉森的凈資產是多少?

People ask me how much I get paid all the time. It comes up on podcast interviews, Quora questions, and face-to-face discussions.人們問我&#xff0c;我一直得到多少報酬。 它來自播客訪談&#xff0c;Quora問題和面對面的討論。 And people search this question a…

COVID-19研究助理

These days scientists, researchers, doctors, and medical professionals face challenges to develop answers to their high priority scientific questions.如今&#xff0c;科學家&#xff0c;研究人員&#xff0c;醫生和醫學專家面臨著挑戰&#xff0c;無法為其高度優先…

Node.js umei圖片批量下載Node.js爬蟲1.00

這個爬蟲在abaike爬蟲的基礎上改改圖片路徑和下一頁路徑就出來了&#xff0c;代碼如下&#xff1a; // // umei圖片批量下載Node.js爬蟲1.00 // 2017年11月13日 //// 內置http模塊 var httprequire("http");// 內置文件處理模塊&#xff0c;用于創建目錄和圖片文件 v…

交通銀行信息技術管理部副總經理張漫麗:交通銀行“大數據+人工智能”應用研究...

文 | 交通銀行信息技術管理部副總經理張漫麗 大數據隱含著巨大的社會、經濟、科研價值&#xff0c;已引起了各行各業的高度重視。如果能通過人工智能技術有效地組織和使用大數據&#xff0c;將對社會經濟和科學研究發展產生巨大的推動作用&#xff0c;同時也孕育著前所未有的機…

安軟件一勞永逸_如何克服一勞永逸地公開演講的恐懼

安軟件一勞永逸If you’re like most people, the idea of public speaking terrifies you (it terrifies me too). So how do you get over those jitters, get up on stage, and give an amazing talk? First, a disclaimer: this article is purely about your stage prese…

Go語言實戰 : API服務器 (8) 中間件

為什么需要中間件 我們可能需要對每個請求/返回做一些特定的操作&#xff0c;比如 記錄請求的 log 信息在返回中插入一個 Header部分接口進行鑒權 這些都需要一個統一的入口。這個功能可以通過引入 middleware 中間件來解決。Go 的 net/http 設計的一大特點是特別容易構建中間…

缺失值和異常值的識別與處理_識別異常值-第一部分

缺失值和異常值的識別與處理&#x1f4c8;Python金融系列 (&#x1f4c8;Python for finance series) Warning: There is no magical formula or Holy Grail here, though a new world might open the door for you.警告 &#xff1a; 這里沒有神奇的配方或圣杯&#xff0c;盡管…

SQL Server 常用分頁SQL

今天無聊和朋友討論分頁&#xff0c;發現網上好多都是錯的。網上經常查到的那個Top Not in 或者Max 大部分都不實用&#xff0c;很多都忽略了Order和性能問題。為此上網查了查&#xff0c;順帶把2000和2012版本的也補上了。 先說說網上常見SQL的錯誤或者說局限問題 12345select…

Word中摘要和正文同時分欄后,正文跑到下一頁,怎么辦?或Word分欄后第一頁明明有空位后面的文字卻自動跳到第二頁了,怎么辦?...

問題1&#xff1a;Word中摘要和正文同時分欄后&#xff0c;正文跑到下一頁&#xff0c;怎么辦&#xff1f;或Word分欄后第一頁明明有空位后面的文字卻自動跳到第二頁了&#xff0c;怎么辦&#xff1f; 答&#xff1a;在word2010中&#xff0c;菜單欄中最左側選“文件”->“選…

leetcode 664. 奇怪的打印機(dp)

題目 有臺奇怪的打印機有以下兩個特殊要求&#xff1a; 打印機每次只能打印由 同一個字符 組成的序列。 每次可以在任意起始和結束位置打印新字符&#xff0c;并且會覆蓋掉原來已有的字符。 給你一個字符串 s &#xff0c;你的任務是計算這個打印機打印它需要的最少打印次數。…