Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537 Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537 久久久精品国产,久久免费毛片,欧美激情在线免费观看

          整合營銷服務(wù)商

          電腦端+手機(jī)端+微信端=數(shù)據(jù)同步管理

          免費(fèi)咨詢熱線:

          html頁面結(jié)構(gòu)

          tml文檔結(jié)構(gòu)


          1. HTML 元素

          HTML 文檔由 HTML 元素定義。

          HTML 元素語法

          HTML 元素以開始標(biāo)簽起始 HTML 元素以結(jié)束標(biāo)簽終止
          元素的內(nèi)容是開始標(biāo)簽與結(jié)束標(biāo)簽之間的內(nèi)容
          某些 HTML 元素具有空內(nèi)容(empty content)
          空元素在開始標(biāo)簽中進(jìn)行關(guān)閉(以開始標(biāo)簽的結(jié)束而結(jié)束)
          大多數(shù) HTML 元素可擁有屬性

          2.HTML 屬性

          屬性是 HTML 元素提供的附加信息。

          HTML 屬性

          HTML 元素可以設(shè)置屬性
          屬性可以在元素中添加附加信息
          屬性一般描述于開始標(biāo)簽
          屬性總是以名稱/值對的形式出現(xiàn),比如:name="value"。

          3. 注釋

          注釋是一種特殊的標(biāo)簽,主要是幫助開發(fā)者理解代碼的邏輯。不會在網(wǎng)頁中顯示,但是在源代碼以及開發(fā)者工具中可以看到。很多編輯器中使用 Ctrl + / 組合鍵可以快速注釋。

          4. html結(jié)構(gòu)

          html頁面主要由一個html根元素和兩個子head和body子標(biāo)簽組成。別的更多標(biāo)簽都在這head和body里面。


          <!DOCTYPE html> 聲明為 HTML5 文檔

          html:元素是html頁面的根元素,所有html標(biāo)簽的一個根節(jié)點(diǎn)。

          head:文檔的頭部,描述了文檔的各種屬性和信息,包括文檔的標(biāo)題,在web中的位置以及和其他文檔的關(guān)系。

          meta:使用 <meta> 元素來描述HTML文檔的描述,關(guān)鍵詞,作者,字符集等。

          title:元素描述了文檔的標(biāo)題

          body:元素包含了可見的頁面內(nèi)容,文檔的主體,以后我們的頁面內(nèi)容基本上都是寫到這個標(biāo)簽里面的(比如文本、超鏈接、圖像、表格和列表)。


          <!DOCTYPE html>
          <!--html是html文檔的根元素-->
          <html >
              <!--head定義文檔標(biāo)題等屬性,用戶不可見-->
              <head>
                  <meta charset="UTF-8">
                  <!--title設(shè)置網(wǎng)頁的標(biāo)題-->
                  <title>我的第一個網(wǎng)頁</title>
              </head>
              <!--body顯示給用戶的內(nèi)容-->
              <body>
                  Hello world, 我是一個男孩!
              </body>
          </html>
          




          閱讀原文

          譯自: https://medium.freecodecamp.org/for-your-first-html-code-lets-help-batman-write-a-love-letter-64c203b9360b

          作者: Kunal Sarkar

          譯者: MjSeven

          在一個美好的夜晚,你的肚子拒絕消化你在晚餐吃的大塊披薩,所以你不得不在睡夢中沖進(jìn)洗手間。

          在浴室里,當(dāng)你在思考為什么會發(fā)生這種情況時,你聽到一個來自通風(fēng)口的低沉聲音:“嘿,我是蝙蝠俠?!?/p>

          這時,你會怎么做呢?

          在你恐慌并處于關(guān)鍵時刻之前,蝙蝠俠說:“我需要你的幫助。我是一個超級極客,但我不懂 HTML。我需要用 HTML 寫一封情書,你愿意幫助我嗎?”

          誰會拒絕蝙蝠俠的請求呢,對吧?所以讓我們用 HTML 來寫一封蝙蝠俠的情書。

          你的第一個 HTML 文件

          HTML 網(wǎng)頁與你電腦上的其它文件一樣。就同一個 .doc 文件以 MS Word 打開,.jpg 文件在圖像查看器中打開一樣,一個 .html 文件在瀏覽器中打開。

          那么,讓我們來創(chuàng)建一個 .html 文件。你可以在 Notepad 或其它任何編輯器中完成此任務(wù),但我建議使用 VS Code。 在這里下載并安裝 VS Code 。它是免費(fèi)的,也是我唯一喜歡的微軟產(chǎn)品。

          在系統(tǒng)中創(chuàng)建一個目錄,將其命名為 “HTML Practice”(不帶引號)。在這個目錄中,再創(chuàng)建一個名為 “Batman’s Love Letter”(不帶引號)的目錄,這將是我們的項目根目錄。這意味著我們所有與這個項目相關(guān)的文件都會在這里。

          打開 VS Code,按下 ctrl+n 創(chuàng)建一個新文件,按下 ctrl+s 保存文件。切換到 “Batman’s Love Letter” 文件夾并將其命名為 “l(fā)oveletter.html”,然后單擊保存。

          現(xiàn)在,如果你在文件資源管理器中雙擊它,它將在你的默認(rèn)瀏覽器中打開。我建議使用 Firefox 來進(jìn)行 web 開發(fā),但 Chrome 也可以。

          讓我們將這個過程與我們已經(jīng)熟悉的東西聯(lián)系起來。還記得你第一次拿到電腦嗎?我做的第一件事是打開 MS Paint 并繪制一些東西。你在 Paint 中繪制一些東西并將其另存為圖像,然后你可以在圖像查看器中查看該圖像。之后,如果要再次編輯該圖像,你在 Paint 中重新打開它,編輯并保存它。

          我們目前的流程非常相似。正如我們使用 Paint 創(chuàng)建和編輯圖像一樣,我們使用 VS Code 來創(chuàng)建和編輯 HTML 文件。就像我們使用圖像查看器查看圖像一樣,我們使用瀏覽器來查看我們的 HTML 頁面。

          HTML 中的段落

          我們有一個空的 HTML 文件,以下是蝙蝠俠想在他的情書中寫的第一段。

          “After all the battles we fought together, after all the difficult times we saw together, and after all the good and bad moments we’ve been through, I think it’s time I let you know how I feel about you.”

          復(fù)制這些到 VS Code 中的 loveletter.html。單擊 “View -> Toggle Word Wrap (alt+z)” 自動換行。

          保存并在瀏覽器中打開它。如果它已經(jīng)打開,單擊瀏覽器中的刷新按鈕。

          瞧!那是你的第一個網(wǎng)頁!

          我們的第一段已準(zhǔn)備就緒,但這不是在 HTML 中編寫段落的推薦方法。我們有一種特定的方法讓瀏覽器知道一個文本是一個段落。

          如果你用 <p> 和 </p> 來包裹文本,那么瀏覽器將識別 <p> 和 </p> 中的文本是一個段落。我們這樣做:

          <p>After all the battles we fought together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you.</p>

          通過在 <p> 和 </p>中編寫段落,你創(chuàng)建了一個 HTML 元素。一個網(wǎng)頁就是 HTML 元素的集合。

          讓我們首先來認(rèn)識一些術(shù)語:<p> 是開始標(biāo)簽,</p> 是結(jié)束標(biāo)簽,“p” 是標(biāo)簽名稱。元素開始和結(jié)束標(biāo)簽之間的文本是元素的內(nèi)容。

          “style” 屬性

          在上面,你將看到文本覆蓋屏幕的整個寬度。

          我們不希望這樣。沒有人想要閱讀這么長的行。讓我們設(shè)定段落寬度為 550px。

          我們可以通過使用元素的 style 屬性來實(shí)現(xiàn)。你可以在其 style 屬性中定義元素的樣式(例如,在我們的示例中為寬度)。以下行將在 p 元素上創(chuàng)建一個空樣式屬性:

          <p style="">...</p>

          你看到那個空的 "" 了嗎?這就是我們定義元素外觀的地方。現(xiàn)在我們要將寬度設(shè)置為 550px。我們這樣做:

          <p style="width:550px;">

          After all the battles we fought together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you.

          </p>

          我們將 width 屬性設(shè)置為 550px,用冒號 : 分隔,以分號 ; 結(jié)束。

          另外,注意我們?nèi)绾螌?<p> 和 </p> 放在單獨(dú)的行中,文本內(nèi)容用一個制表符縮進(jìn)。像這樣設(shè)置代碼使其更具可讀性。

          HTML 中的列表

          接下來,蝙蝠俠希望列出他所欽佩的人的一些優(yōu)點(diǎn),例如:

          You complete my darkness with your light. I love:

          - the way you see good in the worst things

          - the way you handle emotionally difficult situations

          - the way you look at Justice

          I have learned a lot from you. You have occupied a special place in my heart over time.

          這看起來很簡單。

          讓我們繼續(xù),在 </p> 下面復(fù)制所需的文本:

          <p style="width:550px;">

          After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you.

          </p>

          <p style="width:550px;">

          You complete my darkness with your light. I love:

          - the way you see good in the worse

          - the way you handle emotionally difficult situations

          - the way you look at Justice

          I have learned a lot from you. You have occupied a special place in my heart over the time.

          </p>

          保存并刷新瀏覽器。



          哇!這里發(fā)生了什么,我們的列表在哪里?

          如果你仔細(xì)觀察,你會發(fā)現(xiàn)沒有顯示換行符。在代碼中我們在新的一行中編寫列表項,但這些項在瀏覽器中顯示在一行中。

          如果你想在 HTML(新行)中插入換行符,你必須使用 <br>。讓我們來使用 <br>,看看它長什么樣:

          <p style="width:550px;">

          After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you.

          </p>

          <p style="width:550px;">

          You complete my darkness with your light. I love: <br>

          - the way you see good in the worse <br>

          - the way you handle emotionally difficult situations <br>

          - the way you look at Justice <br>

          I have learned a lot from you. You have occupied a special place in my heart over the time.

          </p>

          保存并刷新:



          好的,現(xiàn)在它看起來就像我們想要的那樣!

          另外,注意我們沒有寫一個 </br>。有些標(biāo)簽不需要結(jié)束標(biāo)簽(它們被稱為自閉合標(biāo)簽)。

          還有一件事:我們沒有在兩個段落之間使用 <br>,但第二個段落仍然是從一個新行開始,這是因?yàn)?<p> 元素會自動插入換行符。

          我們使用純文本編寫列表,但是有兩個標(biāo)簽可以供我們使用來達(dá)到相同的目的:<ul> and <li>。

          讓我們解釋一下名字的意思:ul 代表 無序列表(Unordered List),li 代表 列表項目(List Item)。讓我們使用它們來展示我們的列表:

          <p style="width:550px;">

          After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you.

          </p>

          <p style="width:550px;">

          You complete my darkness with your light. I love:

          <ul>

          <li>the way you see good in the worse</li>

          <li>the way you handle emotionally difficult situations</li>

          <li>the way you look at Justice</li>

          </ul>

          I have learned a lot from you. You have occupied a special place in my heart over the time.

          </p>

          在復(fù)制代碼之前,注意差異部分:

          • 我們刪除了所有的 <br>,因?yàn)槊總€ <li> 會自動顯示在新行中
          • 我們將每個列表項包含在 <li> 和 </li> 之間
          • 我們將所有列表項的集合包裹在 <ul> 和 </ul> 之間
          • 我們沒有像 <p> 元素那樣定義 <ul> 元素的寬度。這是因?yàn)?<ul> 是 <p> 的子節(jié)點(diǎn),<p> 已經(jīng)被約束到 550px,所以 <ul> 不會超出這個范圍。

          讓我們保存文件并刷新瀏覽器以查看結(jié)果:



          你會立即注意到在每個列表項之前顯示了重點(diǎn)標(biāo)志。我們現(xiàn)在不需要在每個列表項之前寫 “-”。

          經(jīng)過仔細(xì)檢查,你會注意到最后一行超出 550px 寬度。這是為什么?因?yàn)?HTML 不允許 <ul> 元素出現(xiàn)在 <p> 元素中。讓我們將第一行和最后一行放在單獨(dú)的 <p> 元素中:

          <p style="width:550px;">

          After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you.

          </p>

          <p style="width:550px;">

          You complete my darkness with your light. I love:

          </p>

          <ul style="width:550px;">

          <li>the way you see good in the worse</li>

          <li>the way you handle emotionally difficult situations</li>

          <li>the way you look at Justice</li>

          </ul>

          <p style="width:550px;">

          I have learned a lot from you. You have occupied a special place in my heart over the time.

          </p>

          保存并刷新。

          注意,這次我們還定義了 <ul> 元素的寬度。那是因?yàn)槲覀儸F(xiàn)在已經(jīng)將 <ul> 元素放在了 <p> 元素之外。

          定義情書中所有元素的寬度會變得很麻煩。我們有一個特定的元素用于此目的:<div> 元素。一個 <div> 元素就是一個通用容器,用于對內(nèi)容進(jìn)行分組,以便輕松設(shè)置樣式。

          讓我們用 <div> 元素包裝整個情書,并為其賦予寬度:550px 。

          <div style="width:550px;">

          <p>

          After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you.

          </p>

          <p>

          You complete my darkness with your light. I love:

          </p>

          <ul>

          <li>the way you see good in the worse</li>

          <li>the way you handle emotionally difficult situations</li>

          <li>the way you look at Justice</li>

          </ul>

          <p>

          I have learned a lot from you. You have occupied a special place in my heart over the time.

          </p>

          </div>

          棒極了,我們的代碼現(xiàn)在看起來簡潔多了。

          HTML 中的標(biāo)題

          到目前為止,蝙蝠俠對結(jié)果很高興,他希望在情書上標(biāo)題。他想寫一個標(biāo)題: “Bat Letter”。當(dāng)然,你已經(jīng)看到這個名字了,不是嗎?:D

          你可以使用 <h1>、<h2>、<h3>、<h4>、<h5> 和 <h6> 標(biāo)簽來添加標(biāo)題,<h1> 是最大的標(biāo)題和最主要的標(biāo)題,<h6> 是最小的標(biāo)題。



          讓我們在第二段之前使用 <h1> 做主標(biāo)題和一個副標(biāo)題:

          <div style="width:550px;">

          <h1>Bat Letter</h1>

          <p>

          After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you.

          </p>

          <h2>You are the light of my life</h2>

          <p>

          You complete my darkness with your light. I love:

          </p>

          <ul>

          <li>the way you see good in the worse</li>

          <li>the way you handle emotionally difficult situations</li>

          <li>the way you look at Justice</li>

          </ul>

          <p>

          I have learned a lot from you. You have occupied a special place in my heart over the time.

          </p>

          </div>

          保存,刷新。



          HTML 中的圖像

          我們的情書尚未完成,但在繼續(xù)之前,缺少一件大事:蝙蝠俠標(biāo)志。你見過是蝙蝠俠的東西但沒有蝙蝠俠的標(biāo)志嗎?

          并沒有。

          所以,讓我們在情書中添加一個蝙蝠俠標(biāo)志。

          在 HTML 中包含圖像就像在一個 Word 文件中包含圖像一樣。在 MS Word 中,你到 “菜單 -> 插入 -> 圖像 -> 然后導(dǎo)航到圖像位置為止 -> 選擇圖像 -> 單擊插入”。

          在 HTML 中,我們使用 <img> 標(biāo)簽讓瀏覽器知道我們需要加載的圖像,而不是單擊菜單。我們在 src 屬性中寫入文件的位置和名稱。如果圖像在項目根目錄中,我們可以簡單地在 src 屬性中寫入圖像文件的名稱。

          在我們深入編碼之前,從 這里 下載蝙蝠俠標(biāo)志。你可能希望裁剪圖像中的額外空白區(qū)域。復(fù)制項目根目錄中的圖像并將其重命名為 “bat-logo.jpeg”。

          <div style="width:550px;">

          <h1>Bat Letter</h1>

          <img src="bat-logo.jpeg">

          <p>

          After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you.

          </p>

          <h2>You are the light of my life</h2>

          <p>

          You complete my darkness with your light. I love:

          </p>

          <ul>

          <li>the way you see good in the worse</li>

          <li>the way you handle emotionally difficult situations</li>

          <li>the way you look at Justice</li>

          </ul>

          <p>

          I have learned a lot from you. You have occupied a special place in my heart over the time.

          </p>

          </div>

          我們在第 3 行包含了 <img> 標(biāo)簽。這個標(biāo)簽也是一個自閉合的標(biāo)簽,所以我們不需要寫 </img>。在 src 屬性中,我們給出了圖像文件的名稱。這個名稱應(yīng)與圖像名稱完全相同,包括擴(kuò)展名(.jpeg)及其大小寫。

          保存并刷新,查看結(jié)果。



          該死的!剛剛發(fā)生了什么?

          當(dāng)使用 <img> 標(biāo)簽包含圖像時,默認(rèn)情況下,圖像將以其原始分辨率顯示。在我們的例子中,圖像比 550px 寬得多。讓我們使用 style 屬性定義它的寬度:

          <div style="width:550px;">

          <h1>Bat Letter</h1>

          <img src="bat-logo.jpeg" style="width:100%">

          <p>

          After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you.

          </p>

          <h2>You are the light of my life</h2>

          <p>

          You complete my darkness with your light. I love:

          </p>

          <ul>

          <li>the way you see good in the worse</li>

          <li>the way you handle emotionally difficult situations</li>

          <li>the way you look at Justice</li>

          </ul>

          <p>

          I have learned a lot from you. You have occupied a special place in my heart over the time.

          </p>

          </div>

          你會注意到,這次我們定義寬度使用了 “%” 而不是 “px”。當(dāng)我們在 “%” 中定義寬度時,它將占據(jù)父元素寬度的百分比。因此,100% 的 550px 將為我們提供 550px。

          保存并刷新,查看結(jié)果。



          太棒了!這讓蝙蝠俠的臉露出了羞澀的微笑 :)。

          HTML 中的粗體和斜體

          現(xiàn)在蝙蝠俠想在最后幾段中承認(rèn)他的愛。他有以下文本供你用 HTML 編寫:

          “I have a confession to make

          It feels like my chest does have a heart. You make my heart beat. Your smile brings a smile to my face, your pain brings pain to my heart.

          I don’t show my emotions, but I think this man behind the mask is falling for you.”

          當(dāng)閱讀到這里時,你會問蝙蝠俠:“等等,這是給誰的?”蝙蝠俠說:

          “這是給超人的?!?/p>



          你說:哦!我還以為是給神奇女俠的呢。

          蝙蝠俠說:不,這是給超人的,請在最后寫上 “I love you Superman.”。

          好的,我們來寫:

          <div style="width:550px;">

          <h1>Bat Letter</h1>

          <img src="bat-logo.jpeg" style="width:100%">

          <p>

          After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you.

          </p>

          <h2>You are the light of my life</h2>

          <p>

          You complete my darkness with your light. I love:

          </p>

          <ul>

          <li>the way you see good in the worse</li>

          <li>the way you handle emotionally difficult situations</li>

          <li>the way you look at Justice</li>

          </ul>

          <p>

          I have learned a lot from you. You have occupied a special place in my heart over the time.

          </p>

          <h2>I have a confession to make</h2>

          <p>

          It feels like my chest does have a heart. You make my heart beat. Your smile brings smile on my face, your pain brings pain to my heart.

          </p>

          <p>

          I don't show my emotions, but I think this man behind the mask is falling for you.

          </p>

          <p>I love you Superman.</p>

          <p>

          Your not-so-secret-lover, <br>

          Batman

          </p>

          </div>

          這封信差不多完成了,蝙蝠俠另外想再做兩次改變。蝙蝠俠希望在最后段落的第一句中的 “does” 一詞是斜體,而 “I love you Superman” 這句話是粗體的。

          我們使用 <em> 和 <strong> 以斜體和粗體顯示文本。讓我們來更新這些更改:

          <div style="width:550px;">

          <h1>Bat Letter</h1>

          <img src="bat-logo.jpeg" style="width:100%">

          <p>

          After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you.

          </p>

          <h2>You are the light of my life</h2>

          <p>

          You complete my darkness with your light. I love:

          </p>

          <ul>

          <li>the way you see good in the worse</li>

          <li>the way you handle emotionally difficult situations</li>

          <li>the way you look at Justice</li>

          </ul>

          <p>

          I have learned a lot from you. You have occupied a special place in my heart over the time.

          </p>

          <h2>I have a confession to make</h2>

          <p>

          It feels like my chest <em>does</em> have a heart. You make my heart beat. Your smile brings smile on my face, your pain brings pain to my heart.

          </p>

          <p>

          I don't show my emotions, but I think this man behind the mask is falling for you.

          </p>

          <p><strong>I love you Superman.</strong></p>

          <p>

          Your not-so-secret-lover, <br>

          Batman

          </p>

          </div>



          HTML 中的樣式

          你可以通過三種方式設(shè)置樣式或定義 HTML 元素的外觀:

          • 內(nèi)聯(lián)樣式:我們使用元素的 style 屬性來編寫樣式。這是我們迄今為止使用的,但這不是一個好的實(shí)踐。
          • 嵌入式樣式:我們在由 <style> 和 </style> 包裹的 “style” 元素中編寫所有樣式。
          • 鏈接樣式表:我們在具有 .css 擴(kuò)展名的單獨(dú)文件中編寫所有元素的樣式。此文件稱為樣式表。

          讓我們來看看如何定義 <div> 的內(nèi)聯(lián)樣式:

          <div style="width:550px;">

          我們可以在 <style> 和 </style> 里面寫同樣的樣式:

          div{

          width:550px;

          }

          在嵌入式樣式中,我們編寫的樣式是與元素分開的。所以我們需要一種方法來關(guān)聯(lián)元素及其樣式。第一個單詞 “div” 就做了這樣的活。它讓瀏覽器知道花括號 {...} 里面的所有樣式都屬于 “div” 元素。由于這種語法確定要應(yīng)用樣式的元素,因此它稱為一個選擇器。

          我們編寫樣式的方式保持不變:屬性(width)和值(550px)用冒號(:)分隔,以分號(;)結(jié)束。

          讓我們從 <div> 和 <img> 元素中刪除內(nèi)聯(lián)樣式,將其寫入 <style> 元素:

          <style>

          div{

          width:550px;

          }

          img{

          width:100%;

          }

          </style>

          <div>

          <h1>Bat Letter</h1>

          <img src="bat-logo.jpeg">

          <p>

          After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you.

          </p>

          <h2>You are the light of my life</h2>

          <p>

          You complete my darkness with your light. I love:

          </p>

          <ul>

          <li>the way you see good in the worse</li>

          <li>the way you handle emotionally difficult situations</li>

          <li>the way you look at Justice</li>

          </ul>

          <p>

          I have learned a lot from you. You have occupied a special place in my heart over the time.

          </p>

          <h2>I have a confession to make</h2>

          <p>

          It feels like my chest <em>does</em> have a heart. You make my heart beat. Your smile brings smile on my face, your pain brings pain to my heart.

          </p>

          <p>

          I don't show my emotions, but I think this man behind the mask is falling for you.

          </p>

          <p><strong>I love you Superman.</strong></p>

          <p>

          Your not-so-secret-lover, <br>

          Batman

          </p>

          </div>

          保存并刷新,結(jié)果應(yīng)保持不變。

          但是有一個大問題,如果我們的 HTML 文件中有多個 <div> 和 <img> 元素該怎么辦?這樣我們在 <style> 元素中為 div 和 img 定義的樣式就會應(yīng)用于頁面上的每個 div 和 img。

          如果你在以后的代碼中添加另一個 div,那么該 div 也將變?yōu)?550px 寬。我們并不希望這樣。

          我們想要將我們的樣式應(yīng)用于現(xiàn)在正在使用的特定 div 和 img。為此,我們需要為 div 和 img 元素提供唯一的 id。以下是使用 id 屬性為元素賦予 id 的方法:

          <div id="letter-container">

          以下是如何在嵌入式樣式中將此 id 用作選擇器:

          #letter-container{

          ...

          }

          注意 # 符號。它表示它是一個 id,{...} 中的樣式應(yīng)該只應(yīng)用于具有該特定 id 的元素。

          讓我們來應(yīng)用它:

          <style>

          #letter-container{

          width:550px;

          }

          #header-bat-logo{

          width:100%;

          }

          </style>

          <div id="letter-container">

          <h1>Bat Letter</h1>

          <img id="header-bat-logo" src="bat-logo.jpeg">

          <p>

          After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you.

          </p>

          <h2>You are the light of my life</h2>

          <p>

          You complete my darkness with your light. I love:

          </p>

          <ul>

          <li>the way you see good in the worse</li>

          <li>the way you handle emotionally difficult situations</li>

          <li>the way you look at Justice</li>

          </ul>

          <p>

          I have learned a lot from you. You have occupied a special place in my heart over the time.

          </p>

          <h2>I have a confession to make</h2>

          <p>

          It feels like my chest <em>does</em> have a heart. You make my heart beat. Your smile brings smile on my face, your pain brings pain to my heart.

          </p>

          <p>

          I don't show my emotions, but I think this man behind the mask is falling for you.

          </p>

          <p><strong>I love you Superman.</strong></p>

          <p>

          Your not-so-secret-lover, <br>

          Batman

          </p>

          </div>

          HTML 已經(jīng)準(zhǔn)備好了嵌入式樣式。

          但是,你可以看到,隨著我們包含越來越多的樣式,<style></style> 將變得很大。這可能很快會混亂我們的主 HTML 文件。

          因此,讓我們更進(jìn)一步,通過將 <style> 標(biāo)簽內(nèi)的內(nèi)容復(fù)制到一個新文件來使用鏈接樣式。

          在項目根目錄中創(chuàng)建一個新文件,將其另存為 “style.css”:

          #letter-container{

          width:550px;

          }

          #header-bat-logo{

          width:100%;

          }

          我們不需要在 CSS 文件中寫 <style> 和 </style>。

          我們需要使用 HTML 文件中的 <link> 標(biāo)簽來將新創(chuàng)建的 CSS 文件鏈接到 HTML 文件。以下是我們?nèi)绾巫龅竭@一點(diǎn):

          <link rel="stylesheet" type="text/css" href="style.css">

          我們使用 <link> 元素在 HTML 文檔中包含外部資源,它主要用于鏈接樣式表。我們使用的三個屬性是:

          • rel:關(guān)系。鏈接文件與文檔的關(guān)系。具有 .css 擴(kuò)展名的文件稱為樣式表,因此我們保留 rel=“stylesheet”。
          • type:鏈接文件的類型;對于一個 CSS 文件來說它是 “text/css”。
          • href:超文本參考。鏈接文件的位置。

          link 元素的結(jié)尾沒有 </link>。因此,<link> 也是一個自閉合的標(biāo)簽。

          <link rel="gf" type="cute" href="girl.next.door">

          如果只是得到一個女朋友,那么很容易:D

          可惜沒有那么簡單,讓我們繼續(xù)前進(jìn)。

          這是我們 “l(fā)oveletter.html” 的內(nèi)容:

          <link rel="stylesheet" type="text/css" href="style.css">

          <div id="letter-container">

          <h1>Bat Letter</h1>

          <img id="header-bat-logo" src="bat-logo.jpeg">

          <p>

          After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you.

          </p>

          <h2>You are the light of my life</h2>

          <p>

          You complete my darkness with your light. I love:

          </p>

          <ul>

          <li>the way you see good in the worse</li>

          <li>the way you handle emotionally difficult situations</li>

          <li>the way you look at Justice</li>

          </ul>

          <p>

          I have learned a lot from you. You have occupied a special place in my heart over the time.

          </p>

          <h2>I have a confession to make</h2>

          <p>

          It feels like my chest <em>does</em> have a heart. You make my heart beat. Your smile brings smile on my face, your pain brings pain to my heart.

          </p>

          <p>

          I don't show my emotions, but I think this man behind the mask is falling for you.

          </p>

          <p><strong>I love you Superman.</strong></p>

          <p>

          Your not-so-secret-lover, <br>

          Batman

          </p>

          </div>

          “style.css” 內(nèi)容:

          #letter-container{

          width:550px;

          }

          #header-bat-logo{

          width:100%;

          }

          保存文件并刷新,瀏覽器中的輸出應(yīng)保持不變。

          一些手續(xù)

          我們的情書已經(jīng)準(zhǔn)備好給蝙蝠俠,但還有一些正式的片段。

          與其他任何編程語言一樣,HTML 自出生以來(1990 年)經(jīng)歷過許多版本,當(dāng)前版本是 HTML5。

          那么,瀏覽器如何知道你使用哪個版本的 HTML 來編寫頁面呢?要告訴瀏覽器你正在使用 HTML5,你需要在頁面頂部包含 <!DOCTYPE html>。對于舊版本的 HTML,這行不同,但你不需要了解它們,因?yàn)槲覀儾辉偈褂盟鼈兞恕?/p>

          此外,在之前的 HTML 版本中,我們曾經(jīng)將整個文檔封裝在 <html></html> 標(biāo)簽內(nèi)。整個文件分為兩個主要部分:頭部在 <head></head> 里面,主體在 <body></body> 里面。這在 HTML5 中不是必須的,但由于兼容性原因,我們?nèi)匀贿@樣做。讓我們用 <Doctype>, <html>、 <head> 和 <body> 更新我們的代碼:

          <!DOCTYPE html>

          <html>

          <head>

          <link rel="stylesheet" type="text/css" href="style.css">

          </head>

          <body>

          <div id="letter-container">

          <h1>Bat Letter</h1>

          <img id="header-bat-logo" src="bat-logo.jpeg">

          <p>

          After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you.

          </p>

          <h2>You are the light of my life</h2>

          <p>

          You complete my darkness with your light. I love:

          </p>

          <ul>

          <li>the way you see good in the worse</li>

          <li>the way you handle emotionally difficult situations</li>

          <li>the way you look at Justice</li>

          </ul>

          <p>

          I have learned a lot from you. You have occupied a special place in my heart over the time.

          </p>

          <h2>I have a confession to make</h2>

          <p>

          It feels like my chest <em>does</em> have a heart. You make my heart beat. Your smile brings smile on my face, your pain brings pain to my heart.

          </p>

          <p>

          I don't show my emotions, but I think this man behind the mask is falling for you.

          </p>

          <p><strong>I love you Superman.</strong></p>

          <p>

          Your not-so-secret-lover, <br>

          Batman

          </p>

          </div>

          </body>

          </html>

          主要內(nèi)容在 <body> 里面,元信息在 <head> 里面。所以我們把 <div> 保存在 <body> 里面并加載 <head> 里面的樣式表。

          保存并刷新,你的 HTML 頁面應(yīng)顯示與之前相同的內(nèi)容。

          HTML 的標(biāo)題

          我發(fā)誓,這是最后一次改變。

          你可能已經(jīng)注意到選項卡的標(biāo)題正在顯示 HTML 文件的路徑:



          我們可以使用 <title> 標(biāo)簽來定義 HTML 文件的標(biāo)題。標(biāo)題標(biāo)簽也像鏈接標(biāo)簽一樣在 <head> 內(nèi)部。讓我們我們在標(biāo)題中加上 “Bat Letter”:

          <!DOCTYPE html>

          <html>

          <head>

          <title>Bat Letter</title>

          <link rel="stylesheet" type="text/css" href="style.css">

          </head>

          <body>

          <div id="letter-container">

          <h1>Bat Letter</h1>

          <img id="header-bat-logo" src="bat-logo.jpeg">

          <p>

          After all the battles we faught together, after all the difficult times we saw together, after all the good and bad moments we've been through, I think it's time I let you know how I feel about you.

          </p>

          <h2>You are the light of my life</h2>

          <p>

          You complete my darkness with your light. I love:

          </p>

          <ul>

          <li>the way you see good in the worse</li>

          <li>the way you handle emotionally difficult situations</li>

          <li>the way you look at Justice</li>

          </ul>

          <p>

          I have learned a lot from you. You have occupied a special place in my heart over the time.

          </p>

          <h2>I have a confession to make</h2>

          <p>

          It feels like my chest <em>does</em> have a heart. You make my heart beat. Your smile brings smile on my face, your pain brings pain to my heart.

          </p>

          <p>

          I don't show my emotions, but I think this man behind the mask is falling for you.

          </p>

          <p><strong>I love you Superman.</strong></p>

          <p>

          Your not-so-secret-lover, <br>

          Batman

          </p>

          </div>

          </body>

          </html>

          保存并刷新,你將看到在選項卡上顯示的是 “Bat Letter” 而不是文件路徑。

          蝙蝠俠的情書現(xiàn)在已經(jīng)完成。

          恭喜!你用 HTML 制作了蝙蝠俠的情書。



          我們學(xué)到了什么

          我們學(xué)習(xí)了以下新概念:

          • 一個 HTML 文檔的結(jié)構(gòu)
          • 在 HTML 中如何寫元素(<p></p>)
          • 如何使用 style 屬性在元素內(nèi)編寫樣式(這稱為內(nèi)聯(lián)樣式,盡可能避免這種情況)
          • 如何在 <style>...</style> 中編寫元素的樣式(這稱為嵌入式樣式)
          • 在 HTML 中如何使用 <link> 在單獨(dú)的文件中編寫樣式并鏈接它(這稱為鏈接樣式表)
          • 什么是標(biāo)簽名稱,屬性,開始標(biāo)簽和結(jié)束標(biāo)簽
          • 如何使用 id 屬性為一個元素賦予 id
          • CSS 中的標(biāo)簽選擇器和 id 選擇器

          我們學(xué)習(xí)了以下 HTML 標(biāo)簽:

          • <p>:用于段落
          • <br>:用于換行
          • <ul>、<li>:顯示列表
          • <div>:用于分組我們信件的元素
          • <h1>、<h2>:用于標(biāo)題和子標(biāo)題
          • <img>:用于插入圖像
          • <strong>、<em>:用于粗體和斜體文字樣式
          • <style>:用于嵌入式樣式
          • <link>:用于包含外部樣式表
          • <html>:用于包裹整個 HTML 文檔
          • <!DOCTYPE html>:讓瀏覽器知道我們正在使用 HTML5
          • <head>:包裹元信息,如 <link> 和 <title>
          • <body>:用于實(shí)際顯示的 HTML 頁面的主體
          • <title>:用于 HTML 頁面的標(biāo)題

          我們學(xué)習(xí)了以下 CSS 屬性:

          • width:用于定義元素的寬度
          • CSS 單位:“px” 和 “%”

          朋友們,這就是今天的全部了,下一個教程中見。


          作者簡介:開發(fā)者 + 作者 | supersarkar.com | twitter.com/supersarkar


          via: https://medium.freecodecamp.org/for-your-first-html-code-lets-help-batman-write-a-love-letter-64c203b9360b

          作者: Kunal Sarkar 譯者: MjSeven 校對: wxy

          本文由 LCTT 原創(chuàng)編譯, Linux中國 榮譽(yù)推出

          點(diǎn)擊“了解更多”可訪問文內(nèi)鏈接

          什么學(xué)習(xí)HTML?

          理解HTML代碼是制作網(wǎng)頁的基本技能。在互聯(lián)網(wǎng)高度發(fā)達(dá)的今天,網(wǎng)頁制作技術(shù)開始變的和修圖、處理視頻一樣重要。

          第一,學(xué)會制作網(wǎng)頁就可以把自己想要展示的信息讓其他人使用瀏覽器觀看,無論是文字、照片還是視頻都可以通過瀏覽器觀看,甚至是分享自己制作的小游戲。

          第二,理解網(wǎng)頁運(yùn)行的基本原理后可以更好的瀏覽他人的網(wǎng)頁,尋找有用信息,更合理的使用第三方工具,簡單高效的制作自己的網(wǎng)頁。

          HTML學(xué)習(xí)難度與重要性

          HTML代碼本身非常容易理解,使用也非常簡單,但是單純使用HTML代碼寫出的網(wǎng)頁效果和我們平時看到的網(wǎng)頁相差甚遠(yuǎn)。要想做出一個漂亮的頁面,我們還需要CSS和JavaScript的幫助。

          HTML、CSS、JavaScript這些不同的代碼都有什么作用呢?簡單來說,HTML代碼可以為網(wǎng)頁提供基本內(nèi)容,比如文字、圖片、音樂、視頻等。CSS代碼可以為頁面安排布局,比如標(biāo)題的位置、字體、顏色、大小等,籠統(tǒng)的說就是為HTML代碼添加的內(nèi)容增加樣式信息,例如修改位置、尺寸、顏色等屬性。JavaScript代碼可以為頁面提供交互(互動)功能,例如通過按鈕控制頁面內(nèi)容的隱藏、出現(xiàn),或者為多張圖片添加輪播功能等。

          對比起來,HTML的學(xué)習(xí)難度最低,但作用是最重要的,因?yàn)橐磺许撁娴幕A(chǔ)是內(nèi)容,沒有內(nèi)容,樣式與交互都不存在。

          認(rèn)識HTML基本結(jié)構(gòu)

          第一行 <!DOCTYPE HTML>

          第二行 <html>

          第三行 <head>

          第四行 </head>

          第五行 <body>

          第六行 </body>

          第七行 </html>

          以上七行代碼是一個網(wǎng)頁文件的HTML代碼的基本結(jié)構(gòu)。

          大家觀察一下可以發(fā)現(xiàn)一個規(guī)律,每一行的內(nèi)容都是寫在“<>”里面的。原因說來話長,先記住就行。每個寫在“<>”里面的內(nèi)容叫做“標(biāo)簽”。以后“標(biāo)簽”這個詞會經(jīng)常出現(xiàn)。

          第一行<!DOCTYPE HTML>標(biāo)簽指示 web 瀏覽器關(guān)于頁面使用哪個 HTML 版本進(jìn)行編寫的指令(這句話可以暫時不必理解)。重要的是這句傲嬌的代碼只能存在在HTML代碼的第一行!

          第二行<html>標(biāo)簽與第七行的</html>標(biāo)簽是一對,“<html>”叫做開始標(biāo)簽,“</html>”叫做結(jié)束標(biāo)簽。他們之間的區(qū)別在于結(jié)束標(biāo)簽比開始標(biāo)簽多一個“/”。這是HTML代碼的一個重要規(guī)律,以后我將要學(xué)到的大部分標(biāo)簽都是這樣的,可能瀏覽器有些強(qiáng)迫癥吧,如果沒有結(jié)束標(biāo)簽它會很不舒服,有可能會消極怠工而產(chǎn)生麻煩(不能正常顯示)。不過遺憾的是<!DOCTYPE HTML>太傲嬌,至今沒有另一半。<html> 與 </html> 標(biāo)簽限定了文檔的開始點(diǎn)和結(jié)束點(diǎn)。

          第三行與第四行組成一對,叫做“head”標(biāo)簽。顧名思義,這個“頭”標(biāo)簽里的內(nèi)容統(tǒng)領(lǐng)全局,比如控制布局與樣式的CSS代碼文件和添加互動功能的JavaScript代碼文件在這里添加或?qū)耄凰阉黜撁嬗玫年P(guān)鍵詞信息在這里添加;頁面信息的編碼方式也是由此指定;瀏覽器窗口的標(biāo)題也在這里顯示。

          第五行與第六行組成一對,叫做“body”標(biāo)簽。用來顯示所有的頁面內(nèi)容信息。

          畫個圖來表示一下這四個標(biāo)簽的層級關(guān)系(就是誰包含誰的意思,或者誰在誰的勢力范圍內(nèi)出現(xiàn)):

          邊學(xué)邊練------寫一個最簡單的頁面

          正所謂萬丈高樓平地起,下面我們就動手做我們的第一個網(wǎng)頁文件。

          工具:電腦,安裝一個瀏覽器(IE 火狐 谷歌瀏覽器都可以),確定“記事本”工具可用。

          有了以上工具我們就可以寫了。

          Step1 新建一個.txt文件。

          操作如下:

          (1)選擇合適的磁盤,比如D盤或F盤新建一個文件夾,命名為“網(wǎng)頁”。點(diǎn)擊進(jìn)入。

          (2)在空白處點(diǎn)擊鼠標(biāo)右鍵新建一個文本文件,命名為“第一個頁面”。這時我們就有了一個“第一個頁面.txt”文件了。

          如果你的電腦不顯示“.txt”這樣的文件后綴,可以在屏幕左上方尋找“查看”菜單,如圖2

          圖 2

          點(diǎn)擊后,出現(xiàn)如下菜單如圖3,點(diǎn)擊“選項”。

          圖 3

          點(diǎn)擊“查看”,去掉“隱藏已知文件類型的擴(kuò)展名”選項前的“對號”,如圖4所示。這時就能顯示或修改文件后綴了。

          圖 4

          Step2 添加內(nèi)容

          (1)雙擊打開“第一個頁面.txt”文件,把HTML基本結(jié)構(gòu)共七行代碼輸入進(jìn)去。

          (2)保存,關(guān)閉文件,在“第一個頁面.txt”文件上點(diǎn)擊鼠標(biāo)右鍵,選擇“重命名”,將“.txt”修改為“.html”。這時,系統(tǒng)會提示,如圖1,大膽點(diǎn)“是”。

          圖 1

          這時我們的文件就變成了html網(wǎng)頁文件了。

          我們雙擊這個文件發(fā)現(xiàn)瀏覽器內(nèi)一片空白,這就好比我們在桌子上擺了個碟子,里面并沒有放美食。瀏覽器中的一片白就是空碟子的顏色,而HTML基本結(jié)構(gòu)就是這個碟子。

          下面我們往碟子里加點(diǎn)東西。

          Step3 添加內(nèi)容

          (1)在“第一個頁面.html”文件上點(diǎn)擊鼠標(biāo)右鍵,選擇“打開方式”,選擇“記事本”,如果沒有“記事本”選項,請點(diǎn)擊“選擇其他應(yīng)用”,點(diǎn)擊選擇最下面的“更多應(yīng)用”,選擇“記事本”。下一次選擇“打開方式”時,“記事本”就會出現(xiàn)了。

          (2)在<head></head>標(biāo)簽之間添加“<title>學(xué)習(xí)寫第一個網(wǎng)頁</title>”。在<body></body>之間添加“<h1>第一個網(wǎng)頁</h1>”;“<p>隨著學(xué)的內(nèi)容越來越多,網(wǎng)頁就會越來越漂亮了!</p>”完成如圖5

          圖 5

          (3)保存,關(guān)閉,雙擊打開!效果如圖6

          圖6

          今天的邊學(xué)邊做就到這里,下一次會詳細(xì)解釋<head>標(biāo)簽、<body>標(biāo)簽中常出現(xiàn)的子標(biāo)簽以及它們各自的作用。

          第二篇《邊學(xué)邊做網(wǎng)頁篇——<head>標(biāo)簽里裝點(diǎn)啥?》http://mp.toutiao.com/preview_article/?pgc_id=6738988870622249479


          主站蜘蛛池模板: 视频一区二区三区在线观看| 无码一区二区三区亚洲人妻| 手机福利视频一区二区| 搜日本一区二区三区免费高清视频 | 亚洲中文字幕一区精品自拍| 搜日本一区二区三区免费高清视频 | 亚欧免费视频一区二区三区| 日韩一区二区免费视频| 亚洲av鲁丝一区二区三区| 国产精品一区二区三区久久 | 亚洲AⅤ无码一区二区三区在线 | 国产精品夜色一区二区三区| 视频在线观看一区二区| 色一情一乱一伦一区二区三欧美| 中文无码AV一区二区三区 | 久久精品亚洲一区二区三区浴池| 亚洲国产成人久久一区久久| 国产未成女一区二区三区| 精品无码人妻一区二区三区品 | 91大神在线精品视频一区| 伊人激情AV一区二区三区| 国产一区二区三区免费看| 精品一区中文字幕| 日本精品夜色视频一区二区| 无码人妻精品一区二| 亚洲国产av一区二区三区| 日本精品一区二区三区四区| 国产日韩高清一区二区三区| 亚洲一区二区三区国产精品| 本免费AV无码专区一区| 国产一区二区三区免费| 亚洲国产精品一区二区久久| 国产成人久久精品一区二区三区 | 国产日韩精品一区二区在线观看播放| 亚洲AV成人精品一区二区三区| 亚洲精品伦理熟女国产一区二区 | 中文字幕一区二区在线播放| 国产免费无码一区二区| 麻豆AV无码精品一区二区| 国产精品亚洲一区二区三区在线观看 | 精品无码人妻一区二区三区|