DIV CSS 佈局教程網

您现在的位置: DIV+CSS佈局教程網 >> 網頁腳本 >  >> HTML基礎知識 >> HTML和Xhtml
5 個好用卻不常見的 HTML 標籤與屬性
編輯:HTML和Xhtml     

有些標籤明明很實用,卻很少在一般網站上出現,於是每次遇到都覺得新鮮。以下五個算是筆記性質的整理,多數屬於 HTML5 新增,使用時仍要留意瀏覽器支援情況。

1. contenteditable:讓任何區域變成可編輯

<table border="2" contenteditable="true">
  <caption>Monthly savings</caption>
  <tr><th>Month</th><th>Savings</th></tr>
  <tr><td>January</td><td><div contenteditable="true">$100</div></td></tr>
  <tr><td>February</td><td><div contenteditable="true">$50</div></td></tr>
</table>

加上這個屬性後,表格內容可以直接改,完全不需要另外放輸入框。子元素若沒有指定,會繼承父層設定,所以很方便(也因此,如果加在 body 上,整頁都會變成可編輯狀態)。

2. fieldset:為表單元素分組

相當於桌面開發裡的 GroupBox,用 legend 指定標題:

<fieldset>
  <legend>Index:</legend>
  <ul>
    <li><a href="#">Index of all articles</a></li>
    <li><a href="#">Things to wake up for today</a></li>
  </ul>
</fieldset>

3. area:在圖片上劃出可點擊區域

搭配 map 與 img 的 usemap 屬性,可以替圖片的特定形狀加上連結:

<img src="planets.gif" usemap="#planetmap" width="145" height="126" alt="Planets">
<map name="planetmap">
  <area alt="Sun" coords="0,0,82,126" shape="rect" href="sun.htm">
  <area alt="Mercury" coords="90,58,3" shape="circle" href="mercur.htm">
</map>

4. output:直接顯示運算結果

<form oninput="x.value=parseInt(a.value)+parseInt(b.value)">
  0 <input type="range" id="a" value="50"> 100
  + <input type="number" id="b" value="50">
  = <output name="x" for="a b"></output>
</form>

拖动滑桿就能看到加總即時更新,語意上比隨便用個 span 合適得多。

5. mark:高亮重點文字

<p>Do not forget to buy <mark>milk</mark> today.</p>

不需要把文字拆開、也不需要用 background-color 硬湊,mark 天生就是「標記重點」的意思。

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