html基礎標簽 學習網站:https://www.acwing.com/ 學習查詢網站:https://developer.mozilla.org/zh-CN/ !+tab自動出現框架 1.1 文檔結構 html的所有標簽都為樹形結構,例如: <!DOCTYPE html> <html lang= ...
html基礎標簽
學習查詢網站:https://developer.mozilla.org/zh-CN/
!+tab自動出現框架
1.1 文檔結構
html的所有標簽都為樹形結構,例如:
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Web應用課</title>
</head>
<body>
<h1>第一講</h1>
</body>
</html>
html標簽
HTML<html>元素 表示一個 HTML 文檔的根(頂級元素),所以它也被稱為根元素。所有其他元素必須是此元素的後代。
head標簽
HTML<head>元素 規定文檔相關的配置信息(元數據),包括文檔的標題,引用的文檔樣式和腳本等。
body標簽
HTML<body>元素表示文檔的內容。document.body 屬性提供了可以輕鬆訪問文檔的 body 元素的腳本。
title標簽
HTML<title>元素 定義文檔的標題,顯示在瀏覽器的標題欄或標簽頁上。它只應該包含文本,若是包含有標簽,則它包含的任何標簽都將被忽略。
常見屬性:
- charset:這個屬性聲明瞭文檔的字元編碼。如果使用了這個屬性,其值必須是與 ASCII 大小寫無關(ASCII case-insensitive)的”utf-8”。
- name:name 和 content 屬性可以一起使用,以名 - 值對的方式給文檔提供元數據,其中 name 作為元數據的名稱,content 作為元數據的值。
icon//logo
<link rel="icon" href="images/icon.png">
單行註釋
ctrl+\
多行註釋
<!-- -->
homework_1
<!-- 頁面標簽的標題為:Web應用課作業
charset為:UTF-8
keywords為:acwing,web,html
description為:本課程為【AcWing工程課系列——Level-3 第一篇】《Web應用課》,講解Web相關知識。
icon設置為:/images/logo.png -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="keywords" content="acwing,web,html">
<meta name="description" content="本課程為【AcWing工程課系列——Level-3 第一篇】《Web應用課》,講解Web相關知識。">
<title>web應用課作業</title>
<link rel="icon" href="/images/icon.png">
</head>
<body>
</body>
</html>
1.2 文本標簽
文本標簽雖然很多,但大部分可看成是預定好樣式的<div>和<span>。
div標簽
<div>元素 (或 HTML 文檔分區元素) 是一個通用型的流內容容器,在不使用CSS的情況下,其對內容或佈局沒有任何影響。
span標簽
span元素是短語內容的通用行內容器,並沒有任何特殊語義。可以使用它來編組元素以達到某種樣式意圖(通過使用類或者 Id 屬性),或者這些元素有著共同的屬性,比如lang。應該在沒有其他合適的語義元素時才使用它。span與div很相似,但div是一個塊元素而span是行內元素
h1-h6標簽
六個不同的級別的標題
p標簽
表示文本的一個段落
pre標簽
表示預定義格式文本。在該元素中的文本通常按照原文件中的編排,以等寬字體的形式展現出來,文本中的空白符(比如空格和換行符)都會顯示出來
br標簽
換行符號
hr標簽
表示段落級元素之間的主題轉換(一條線)
b標簽
加粗
i標簽
斜體
del標簽
表示一些被從文檔中刪除的文字內容,類似於
你好
homework_2
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h2>春江花月夜</h2>
<h5>張若虛</h5>
<p>春江潮水連海平,海上明月共潮生。</p>
<p>灧灧隨波千萬里,何處春江無月明!</p>
<p>江流宛轉繞芳甸,月照花林皆似霰;</p>
<p>空里流霜不覺飛,汀上白沙看不見。</p>
<p>江天一色無纖塵,皎皎空中孤月輪。</p>
<p>江畔何人初見月?江月何年初照人?</p>
<p>人生代代無窮已,江月年年望相似。</p>
<hr>
<pre>
int main()
{
int a, b;
scanf("%d%d", &a, &b);
printf("%d %d\n", a, b);
return 0;
}
</pre>
<p>
<i>春眠不覺曉,</i><b>處處聞啼鳥。</b><del>夜來風雨聲,</del><ins>花落知多少。</ins>
</p>
</body>
</html>
1.3 圖片
html<img>元素將一份圖像嵌入文檔,且預設為行內元素
- <src>屬性
該屬性是必須的,它包含了你想嵌入的圖片的文件路徑
- <alt>屬性
包含一條對圖像的文本屬性,在圖片無法載入時顯示
-
<height>屬性
-
圖像的高度,可以只指定 width 和 height 中的一個值,瀏覽器會根據原始圖像進行縮放。
-
<width>屬性
圖像的寬度
homework _3
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<img src="/images/mountain.jpg" alt="山" width="600">
</body>
</html>
1.4 音頻與視頻
<audio>標簽
HTML <audio> 元素用於在文檔中嵌入音頻內容。 <audio> 元素可以包含一個或多個音頻資源, 這些音頻資源可以使用 src 屬性或者<source> 元素來進行描述:瀏覽器將會選擇最合適的一個來使用。也可以使用 MediaStream 將這個元素用於流式媒體。
- 使用src屬性播放,示例:
<audio controls src="/audios/bgm.mp3">
Your browser does not support the
<code>audio</code> element.
</audio>
-
<audio>與多個<source>元素
這個例子包含了多個 <source> 元素。如果能夠播放的話,瀏覽器就會試圖去載入第一個 source 元素;如果不行,那就退而求其次去載入第二個。
<audio controls>
<source src="/audios/sound1" type="audio/mpeg"/>
<source src="/audios/sound2" type="audio/mpeg"/>
</audio>
<video>標簽
HTML <video> 元素 用於在 HTML 或者 XHTML 文檔中嵌入媒體播放器,用於支持文檔內的視頻播放。你也可以將 <video> 標簽用於音頻內容,但是 <audio> 元素可能在用戶體驗上更合適。
<video controls width="800">
<source src="/videos/video1.mp4"
type="video/mp4">
<source src="/videos/video2.mp4"
type="video/mp4">
Sorry, your browser doesn't support embedded videos.
</video>
homework_4
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<audio src="/audios/bgm.mp3" controls></audio>
<video src="/videos/video2.mp4" width="600" controls></video>
</body>
</html>
1.5 超鏈接
HTML <a> 元素(或稱錨元素)可以通過它的 href 屬性創建通向其他網頁、文件、同一頁面內的位置、電子郵件地址或任何其他 URL 的超鏈接。<a> 中的內容應該指明鏈接的意圖。如果存在 href 屬性,當 <a> 元素聚焦時按下回車鍵就會激活它。
示例:
<a href="https://www.acwing.com/problem/ "target="_blank"> ACWing-官網</a>
<a href="about.html"> <mark>About</mark> </a>
常用選項
點擊鏈接打開新標簽頁面時加入屬性:target="_blank"
homeork_5
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<a href="/about.html">About</a>
<a href="https://www.acwing.com" target="_blank">
<img src="/images/logo.png" alt="logo" width="50">
</a>
</body>
</html>
1.6 表單
<form>標簽
HTML <form> 元素表示文檔中的一個區域,此區域包含交互控制項,用於向 Web 伺服器提交信息
<input>標簽
HTML <input>用來填寫內容,常見類型有:
- <input type="text">:創建基礎的單行文本框。
- <input type="number">:用於讓用戶輸入一個數字。其包括內置驗證以拒絕非數字輸入。瀏覽器可能會選擇提供步進箭頭,讓用戶可以使用滑鼠增加和減少輸入的值,或者只需用指尖敲擊即可。
- <input type="email">:帶有 “email” (電子郵箱) 類型標記的輸入框元素 (<input>) 能夠讓用戶輸入或編輯一個電子郵箱地址,此外,如果指定了multiple屬性,用戶還可以輸入多個電子郵箱地址。在表單提交前,輸入框會自動驗證輸入值是否是一個或多個合法的電子郵箱地址 (非空值且符合電子郵箱地址格式). CSS 偽標簽 :valid 和 :invalid 能夠在校驗後自動應用。
- <input type="password">: 元素 里有一種叫做 “password” 的值,給我們一個方法讓用戶更加安全的輸入密碼。這個元素是作為一行純文本編輯器控制項呈現的,其中文本被遮蔽以致於無法讀取,通常通過用諸如星號(“*”)或點(“•”)等符號替換每個字元來實現。這個符號會根據用戶的瀏覽器和操作系統來具體顯示哪個。
- <input type="radio">:<input> 的 radio 類型元素預設渲染為小型圓圈圖表,填充即為激活,類似於之前描述額覆選框(checkbox)類型。單選按鈕允許你選擇單一的值來提交表單。
常用屬性有:
- name: 名稱
- id: 唯一ID
- maxlength:最大長度
- minlength:最小長度
- required:是否必填
- placeholder:當表單控制項為空時,控制項中顯示的內容
<textarea>標簽
HTML <textarea> 元素表示一個多行純文本編輯控制項,當你希望用戶輸入一段相當長的、不限格式的文本,例如評論或反饋表單中的一段意見時,這很有用。
<select>與<option>標簽
HTML <select> 元素表示一個提供選項菜單的控制項。
示例:
<label for="pet-select">Choose a pet:</label>
<select name="pets" id="pet-select">
<option value="">--Please choose an option--</option>
<option value="dog">Dog</option>
<option value="cat">Cat</option>
<option value="hamster">Hamster</option>
<option value="parrot">Parrot</option>
<option value="spider">Spider</option>
<option value="goldfish">Goldfish</option>
</select>
<button>標簽
HTML <button> 元素表示一個可點擊的按鈕,可以用在表單或文檔其它需要使用簡單標準按鈕的地方。 預設情況下,HTML 按鈕的顯示樣式接近於 user agent 所在的宿主系統平臺(用戶操作系統)的按鈕, 但你可以使用 CSS 來改變按鈕的樣貌。
homework_6
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form action="/login.html">
<label for="username">用戶名</label>
<input type="text" name="username" id="username" minlength="3" maxlength="15" required placeholder="用戶名">
<label for="age">年齡</label>
<input type="number" name="age" id="age" required placeholder="年齡">
<label for="email">郵箱</label>
<input type="email" name="email" id="email" required placeholder="郵箱">
<label for="password">密碼</label>
<input type="password" name="password" id="password" required placeholder="密碼">
<label for="resume">個人簡介</label>
<textarea name="resume" id="resume" placeholder="個人簡介"></textarea>
<label for="lang">語言</label>
<select name="lang" id="lang">
<option value="Cpp">Cpp</option>
<option value="Java">Java</option>
<option value="Python">Python</option>
</select>
<button type="submit">提交</button>
</form>
</body>
</html>
1.7 表單
<ul>與<li>標簽
HTML <ul> 元素(或稱 HTML 無序列表元素)表示一個內可含多個元素的無序列表或項目符號列表。
示例:
<ul>
<li>first item</li>
<li>second item</li>
<li>third item</li>
</ul>
<ol>與<li>標簽
HTML <ol> 元素表示有序列表,通常渲染為一個帶編號的列表。
<ol>
<li>Fee</li>
<li>Fi</li>
<li>Fo</li>
<li>Fum</li>
</ol>
<dl><dt>與<dd>標簽
HTML <dl> 元素 (或 HTML 描述列表元素)是一個包含術語定義以及描述的列表,通常用於展示辭彙表或者元數據 (鍵 - 值對列表)。
示例:
<dl>
<dt>Name</dt>
<dd>Godzilla</dd>
<dt>Born</dt>
<dd>1952</dd>
<dt>Birthplace</dt>
<dd>Japan</dd>
<dt>Color</dt>
<dd>Green</dd>
<dd>Orange</dd>
</dl>
homework_7
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<ol>
<li>
第一講
</li>
<li>第二講
<ul>
<li>第一小節</li>
<li>第二小節</li>
<li>第三小節</li>
</ul>
</li>
<li>
第三講
<ol>
<li>第一小節</li>
<li>第二小節</li>
<li>第三小節</li>
</ol>
</li>
</ol>
</body>
</html>
1.8 表格
標簽 HTML的 table 元素表示表格數據 — 即通過二維數據表表示的信息。 <thead>標簽 HTML的元素定義了一組定義表格的列頭的行。<tbody>標簽
HTML的元素定義一組數據行。
<tr>標簽
HTML 元素定義表格中的行。 同一行可同時出現 和 元素。
<th>標簽
HTML 元素定義表格內的表頭單元格。
<td>標簽
HTML 元素 定義了一個包含數據的表格單元格。
<caption>標簽
HTML 元素 (or HTML 表格標題元素) 展示一個表格的標題, 它常常作為
<table>的第一個子元素出現,同時顯示在表格內容的最前面,但是,它同樣可以被 CSS 樣式化,所以,它同樣可以出現在相對於表格的任意位置。
示例:
<table>
<caption>My Table</caption>
<thead>
<tr>
<th colspan="2">The table header</th>
</tr>
</thead>
<tbody>
<tr>
<td>The table body</td>
<td>with two columns</td>
</tr>
</tbody>
</table>
homework_8
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<table>
<caption>成績單</caption>
<!-- 表頭 -->
<thead>
<tr>
<th>姓名</th>
<th>數學</th>
<th>語文</th>
<th>英語</th>
</tr>
</thead>
<tbody>
<tr>
<td>Alice</td>
<td>100</td>
<td>99</td>
<td>98</td>
</tr>
<tr>
<td>Bob</td>
<td>99</td>
<td>98</td>
<td>97</td>
</tr>
<tr>
<td>Tom</td>
<td>98</td>
<td>97</td>
<td>96</td>
</tr>
</tbody>
</table>
</body>
</html>
1.9 語義標簽
<header>
HTML <header>
元素用於展示介紹性內容,通常包含一組介紹性的或是輔助導航的實用元素。它可能包含一些標題元素,但也可能包含其他元素,比如 Logo、搜索框、作者名稱,等等。
<nav>
HTML <nav>
元素表示頁面的一部分,其目的是在當前文檔或其他文檔中提供導航鏈接。導航部分的常見示例是菜單,目錄和索引。
<cection>
HTML <section>
元素表示一個包含在 HTML 文檔中的獨立部分,它沒有更具體的語義元素來表示,一般來說會有包含一個標題。
<figure>
HTML <figure>
元素代表一段獨立的內容,經常與說明(caption)<figcaption>
配合使用,並且作為一個獨立的引用單元。當它屬於主內容流(main flow)時,它的位置獨立於主體。這個標簽經常是在主文中引用的圖片,插圖,表格,代碼段等等,當這部分轉移到附錄中或者其他頁面時不會影響到主體。
<article>
HTML <article>
元素表示文檔、頁面、應用或網站中的獨立結構,其意在成為可獨立分配的或可復用的結構,如在發佈中,它可能是論壇帖子、雜誌或新聞文章、博客、用戶提交的評論、互動式組件,或者其他獨立的內容項目。
<aside>
HTML <aside>
元素表示一個和其餘頁面內容幾乎無關的部分,被認為是獨立於該內容的一部分並且可以被單獨的拆分出來而不會使整體受影響。其通常表現為側邊欄或者標註框(call-out boxes)。
<footer>
HTML <footer>
元素表示最近一個章節內容或者根節點(sectioning root )元素的頁腳。一個頁腳通常包含該章節作者、版權數據或者與文檔相關的鏈接等信息。
homework_9
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<header>
<h3>我的收藏夾</h3>
</header>
<section>
<h4>圖片</h4>
<figure>
<img src="/images/logo.png" width="100">
<figcaption>logo</figcaption>
</figure>
<figure>
<img src="/images/mountain.jpg" width="100">
<figcaption>山</figcaption>
</figure>
</section>
<section>
<h4>古詩</h4>
<article>
<h5>春曉</h5>
<p>春眠不覺曉,處處聞啼鳥。夜來風雨聲,花落知多少。</p>
</article>
<article>
<h5>詠柳</h5>
<p>碧玉妝成一樹高,萬條垂下綠絲絛。不知細葉誰裁出,二月春風似剪刀。</p>
</article>
</section>
<footer>
©2018-2022 Me 版權所有
</footer>
</body>
</html>
1.10 特殊符號
homework_10
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<footer>
©<Web>版權所有
</footer>
</body>
</html>