DIV CSS 佈局教程網

您现在的位置: DIV+CSS佈局教程網 >> 網頁腳本 >  >> HTML基礎知識 >> 關於HTML
HTML 語言剖析(六):清單標記
編輯:關於HTML     

清單相關標記包括 <OL>、<LI>、<UL>、<MENU>、<DIR>、<DL>、<DT>、<DD>。

<OL> 與 <LI>:順序清單

<OL> 稱為順序清單標記,<LI> 則用來標示清單項目。所謂順序清單,就是每一項前面加上 1、2、3… 的編號,又稱編號清單。

<OL> 的參數(例如 <ol type="i" start="4"></ol>):

  • type="i" 設定編號款式,共五種,預設為 type="1":
    • 1 阿拉伯數字:1, 2, 3, ...
    • a 小寫字母:a, b, c, ...
    • A 大寫字母:A, B, C, ...
    • i 小寫羅馬數字:i, ii, iii, ...
    • I 大寫羅馬數字:I, II, III, ...
  • start="4" 設定起始編號。不論採用哪一種款式,其值只能是 1、2、3… 等整數,預設為 start="1"。

<LI> 的參數(例如 <li type="square" value="4">):

  • type="square" 僅適用於非順序清單,設定項目符號款式,三種選擇如下,預設為 type="disc":disc 為實心圓點、circle 為空心圓點、square 為實心方塊。
  • value="4" 僅適用於順序清單,設定該項的編號,其後各項以此為起點遞增,但前面各項不受影響。值只能是整數,沒有預設值。

例子:

My best friends:
<ol>
<li>Michelle Wei
<li>Michael Wan
<li>Gloria Lam
</ol>

顯示結果:

My best friends:

  1. Michelle Wei
  2. Michael Wan
  3. Gloria Lam

<UL>:無序清單

<UL> 稱為無序清單標記。所謂無序清單就是每一項前面加上圓點或方塊等符號,故又稱符號清單。

參數(例如 <UL type="square">):type 設定符號款式,三種選擇同前,預設為 disc。

注意:由於 <UL> 與 <LI> 都有 type 參數,兩者盡量只選用其中一個,避免混淆。

例子:

My Homepages:
<ul>
<li>Penpals Garden
<li>ICQ Garden
<li>Software City
<li>Creation of Webpage
</ul>

顯示結果:

My Homepages:

  • Penpals Garden
  • ICQ Garden
  • Software City

<MENU> 與 <DIR>

這兩個標記都不為 W3C 所贊同,建議改用 <ul> 與 <ol>。它們基本上和 <ul> 一樣,在某些瀏覽器中會表現出 <ol> 的效果;舊版的 IE 或 Netscape 中,<DIR> 則不顯示符號或編號。用法與 <ul> 完全相同。

<dir>
<li>Penpals Garden
<li>ICQ Garden
<li>Software City
<li>Creation of Webpage
</dir>

顯示結果:

  • Penpals Garden
  • ICQ Garden
  • Software City
  • <DL> <DT> <DD>:定義清單

    <DL> 稱為定義清單標記,<DT> 用來標示定義條目(術語),<DD> 用來標示定義內容。所謂定義清單是一種兩層的項目清單,不帶符號與編號。

    三個標記都沒有常用參數。<DT> 與 <DD> 可以獨立使用,但部分舊瀏覽器(如 IE 3.0)並不支援。另外 <DD> 常被用來製造段落首行的縮排效果。

    例子:

    <dl>
    <dt>How to use Definition List
    <dd>First, you should not place paragraph tag right after or before a list structure or between the items of a list. In certain contexts, use of extra paragraph tags should always be avoided. When you realize this concept, it is quite easy to write a HTML.
    <dt>Other things to know
    <dd>We usually put only ONE Definition tag following the Definition Term tag; more than one DD tag is not recommended. Besides, unlike Definition List is a nonempty tag, both Definition Term and Definition Description are empty tags.
    </dl>

    顯示結果:

    How to use Definition List
    First, you should not place paragraph tag right after or before a list structure or between the items of a list. In certain contexts, use of extra paragraph tags should always be avoided. When you realize this concept, it is quite easy to write a HTML.
    Other things to know
    We usually put only ONE Definition tag following the Definition Term tag; more than one DD tag is not recommended. Besides, unlike Definition List is a nonempty tag, both Definition Term and Definition Description are empty tags.

    現代觀點

    <MENU> 與 <DIR> 已在 HTML5 中被移除(<menu> 曾被重新定義為語意化的選單容器,但瀏覽器支援仍不一致)。<OL>、<UL>、<DL> 三者則是 HTML5 完整保留的語意標籤,值得放心使用。

    實際開發中有兩個重點:一是清單的 type、start、value 屬性雖仍可用,但若要客製符號樣式(自訂圖示、顏色、編號格式),應改用 CSS 的 list-style-type、list-style-image 與 ::marker 偽元素;二是 <UL> 與 <LI> 雖然允許省略 </LI> 結束標籤,但養成關閉的習慣對後續維護與團隊協作都有明顯好處。

    導覽列(navigation)在語意上正是「一組同類型的連結清單」,因此以 <nav> 包 <ul> 是公認的標準寫法。

    XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
    Copyright © DIV+CSS佈局教程網 All Rights Reserved