怎么用ps做網(wǎng)站首頁圖片尺寸seo中心
在本文中,我們將介紹 HTML 的絕對基礎(chǔ)知識。為了幫助您入門,本文定義了元素、屬性以及您可能聽說過的所有其他重要術(shù)語。它還解釋了這些在 HTML 中的位置。您將學(xué)習(xí) HTML 元素的結(jié)構(gòu)、典型的 HTML 頁面的結(jié)構(gòu)以及其他重要的基本語言功能。在此過程中,也將有機(jī)會玩轉(zhuǎn) HTML!
先決條件: | 已安裝基本軟件,并具有處理文件的基本知識。 |
---|---|
目的: | 獲得對 HTML 的基本熟悉,并練習(xí)編寫一些 HTML 元素。 |
什么是 HTML?
HTML(超文本標(biāo)記語言)是一種標(biāo)記語言,它告訴網(wǎng)絡(luò)瀏覽器如何構(gòu)建您訪問的網(wǎng)頁。它可以像 Web 開發(fā)人員希望的那樣復(fù)雜或簡單。HTML 由一系列元素組成,您可以使用這些元素來包圍、包裝或標(biāo)記內(nèi)容的不同部分,以使其以某種方式顯示或操作。封閉標(biāo)簽可以將內(nèi)容轉(zhuǎn)換為超鏈接以連接到另一個頁面、斜體字等。例如,請考慮以下文本行:
<span style="background-color:var(--code-background-block)">My cat is very grumpy
</span>
如果我們希望文本獨(dú)立存在,我們可以通過將文本包含在段落 ("><p>) 元素中來指定它是一個段落:
<span style="background-color:var(--code-background-block)"><code><span style="color:var(--code-token-attribute-value)"><span style="color:var(--code-token-attribute-value)"><span style="color:var(--code-token-punctuation)"><</span>p</span><span style="color:var(--code-token-punctuation)">></span></span>My cat is very grumpy<span style="color:var(--code-token-attribute-value)"><span style="color:var(--code-token-attribute-value)"><span style="color:var(--code-token-punctuation)"></</span>p</span><span style="color:var(--code-token-punctuation)">></span></span>
</code></span>
注意:HTML 中的標(biāo)簽不區(qū)分大小寫。這意味著它們可以用大寫或小寫字母書寫。例如,"><title>標(biāo)簽可以寫成 、 、 等,這樣就可以工作了。但是,為了保持一致性和可讀性,最佳做法是將所有標(biāo)記寫成小寫字母。<title>
<TITLE>
<Title>
<TiTlE>
HTML 元素剖析
讓我們進(jìn)一步探討上一節(jié)中的段落元素:
我們元素的解剖結(jié)構(gòu)是:
- 開場標(biāo)簽:它由元素的名稱(在此示例中,p 代表段落)組成,并用左尖括號和右尖括號括起來。此開始標(biāo)記標(biāo)記元素開始或開始生效的位置。在此示例中,它位于段落文本的開頭之前。
- 內(nèi)容:這是元素的內(nèi)容。在此示例中,它是段落文本。
- 結(jié)束標(biāo)簽:這與開始標(biāo)記相同,不同之處在于它在元素名稱之前包含一個正斜杠。這標(biāo)記了元素結(jié)束的位置。未能包含結(jié)束標(biāo)記是一個常見的初學(xué)者錯誤,可能會產(chǎn)生特殊的結(jié)果。
該元素是開始標(biāo)記,后跟內(nèi)容,后跟結(jié)束標(biāo)記。
主動學(xué)習(xí):創(chuàng)建您的第一個 HTML 元素
通過用標(biāo)簽包裝“來編輯”可編輯代碼“區(qū)域中的以下行,并要打開元素,請將開始標(biāo)記放在行的開頭。若要關(guān)閉元素,請將結(jié)束標(biāo)記放在行尾。這樣做應(yīng)該會給行斜體文本格式!在“輸出”區(qū)域中實(shí)時查看更改更新。<em>
</em>.
<em>
</em>
如果您犯了錯誤,可以使用“重置”按鈕清除您的工作。如果您真的遇到困難,請按“顯示解決方案”按鈕查看答案。

嵌套元素
元素可以放置在其他元素中。這稱為嵌套。如果我們想說我們的貓非常脾氣暴躁,我們可以將這個詞用"><strong>元素包裝,這意味著這個詞要有strong(er)文本格式:
<span style="background-color:var(--code-background-block)"><code><span style="color:var(--code-token-attribute-value)"><span style="color:var(--code-token-attribute-value)"><span style="color:var(--code-token-punctuation)"><</span>p</span><span style="color:var(--code-token-punctuation)">></span></span>My cat is <span style="color:var(--code-token-attribute-value)"><span style="color:var(--code-token-attribute-value)"><span style="color:var(--code-token-punctuation)"><</span>strong</span><span style="color:var(--code-token-punctuation)">></span></span>very<span style="color:var(--code-token-attribute-value)"><span style="color:var(--code-token-attribute-value)"><span style="color:var(--code-token-punctuation)"></</span>strong</span><span style="color:var(--code-token-punctuation)">></span></span> grumpy.<span style="color:var(--code-token-attribute-value)"><span style="color:var(--code-token-attribute-value)"><span style="color:var(--code-token-punctuation)"></</span>p</span><span style="color:var(--code-token-punctuation)">></span></span>
</code></span>
筑巢有正確和錯誤的方法。在上面的示例中,我們首先打開了元素,然后打開了元素。為了正確嵌套,我們應(yīng)該先關(guān)閉元素,然后再關(guān)閉 .p
strong
strong
p
以下是錯誤嵌套方法的示例:
<span style="background-color:var(--background-critical)"><code><span style="color:var(--code-token-attribute-value)"><span style="color:var(--code-token-attribute-value)"><span style="color:var(--code-token-punctuation)"><</span>p</span><span style="color:var(--code-token-punctuation)">></span></span>My cat is <span style="color:var(--code-token-attribute-value)"><span style="color:var(--code-token-attribute-value)"><span style="color:var(--code-token-punctuation)"><</span>strong</span><span style="color:var(--code-token-punctuation)">></span></span>very grumpy.<span style="color:var(--code-token-attribute-value)"><span style="color:var(--code-token-attribute-value)"><span style="color:var(--code-token-punctuation)"></</span>p</span><span style="color:var(--code-token-punctuation)">></span></span><span style="color:var(--code-token-attribute-value)"><span style="color:var(--code-token-attribute-value)"><span style="color:var(--code-token-punctuation)"></</span>strong</span><span style="color:var(--code-token-punctuation)">></span></span>
</code></span>
標(biāo)簽必須以它們在彼此內(nèi)部或外部的方式打開和關(guān)閉。與上面示例中的重疊類型相同,瀏覽器必須猜測您的意圖。這種猜測可能會導(dǎo)致意想不到的結(jié)果。
虛空元素
并非所有元素都遵循開始標(biāo)簽、內(nèi)容和結(jié)束標(biāo)簽的模式。一些元素由單個標(biāo)簽組成,該標(biāo)簽通常用于在文檔中插入/嵌入某些內(nèi)容。這樣的元素被稱為虛空元素。例如,"><img> 元素將圖像文件嵌入到頁面上:
<span style="background-color:var(--code-background-block)"><code><span style="color:var(--code-token-attribute-value)"><span style="color:var(--code-token-attribute-value)"><span style="color:var(--code-token-punctuation)"><</span>img</span><span style="color:var(--code-token-attribute-name)">src</span><span style="color:var(--code-token-attribute-value)"><span style="color:var(--code-token-punctuation)">=</span><span style="color:var(--code-token-punctuation)">"</span>https://raw.githubusercontent.com/mdn/beginner-html-site/gh-pages/images/firefox-icon.png<span style="color:var(--code-token-punctuation)">"</span></span><span style="color:var(--code-token-attribute-name)">alt</span><span style="color:var(--code-token-attribute-value)"><span style="color:var(--code-token-punctuation)">=</span><span style="color:var(--code-token-punctuation)">"</span>Firefox icon<span style="color:var(--code-token-punctuation)">"</span></span> <span style="color:var(--code-token-punctuation)">/></span>&