龙舍·嬴皇志
透过我的双眼看世界
HTML5的结构和语义——语义性的内联元素(四)

HTML4用5个不同的内联元素表示略有差异的计算机代码:var、code、kbd、tt 和 samp。但是,它无法表示时间、数字等基本数值。HTML 5 提供了几个新的内联元素来满足非技术作者的需求。 
   m
m 元素表示文本被 “加上标志”,但是不一定要强调。可以把它想像成书中突出显示的一节。Google 的缓存页面就是典型的用例。如果链接到一个缓存的副本,搜索词就被加上标志。例如,如果搜索 “Egret”,那么缓存的 Google 页面可能像下面这样:

   1: The Great <m>Egret</m> (also known as the
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   2:</span> American <span style="color: #0000ff">&lt;</span><span style="color: #800000">m</span><span style="color: #0000ff">&gt;</span>Egret<span style="color: #0000ff">&lt;/</span><span style="color: #800000">m</span><span style="color: #0000ff">&gt;</span>)  is a large white wading bird found worldwide.</pre>

<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   3:</span> The Great <span style="color: #0000ff">&lt;</span><span style="color: #800000">m</span><span style="color: #0000ff">&gt;</span>Egret<span style="color: #0000ff">&lt;/</span><span style="color: #800000">m</span><span style="color: #0000ff">&gt;</span> flies with slow wing beats. The</pre>

<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   4:</span> scientific name of the Great <span style="color: #0000ff">&lt;</span><span style="color: #800000">m</span><span style="color: #0000ff">&gt;</span>Egret<span style="color: #0000ff">&lt;/</span><span style="color: #800000">m</span><span style="color: #0000ff">&gt;</span> is <span style="color: #0000ff">&lt;</span><span style="color: #800000">i</span><span style="color: #0000ff">&gt;</span>Casmerodius</pre>

<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   5:</span> albus<span style="color: #0000ff">&lt;/</span><span style="color: #800000">i</span><span style="color: #0000ff">&gt;</span>. </pre></p>

   对于这个元素的名称当前还有争议。在规范发布之前,它可能从 m 改为 mark。 
time

time 元素表示一个时间值,比如 5:35 P.M., EST, April 23, 2007。例如:

   1: <p>I am writing this example at
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   2:</span> <span style="color: #0000ff">&lt;</span><span style="color: #800000">time</span><span style="color: #0000ff">&gt;</span>5:35 P.M. on April 23rd<span style="color: #0000ff">&lt;/</span><span style="color: #800000">time</span><span style="color: #0000ff">&gt;</span>.</pre>

<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   3:</span> <span style="color: #0000ff">&lt;/</span><span style="color: #800000">p</span><span style="color: #0000ff">&gt;</span> </pre></p>

   time 元素可以帮助浏览器和其他程序识别出 HTML 页面中的时间。它不要求对元素内容应用任何特定的格式。但是,每个 time 元素都应该有一个 datetime 属性,其中包含更适合机器识别的时间值,比如:

   1: <p>I am writing this example at
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   2:</span> <span style="color: #0000ff">&lt;</span><span style="color: #800000">time</span> <span style="color: #ff0000">datetime</span><span style="color: #0000ff">="2007-04-23T17:35:00-05:00"</span><span style="color: #0000ff">&gt;</span>5:35 P.M. on April 23rd<span style="color: #0000ff">&lt;/</span><span style="color: #800000">time</span><span style="color: #0000ff">&gt;</span>.</pre>

<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   3:</span> <span style="color: #0000ff">&lt;/</span><span style="color: #800000">p</span><span style="color: #0000ff">&gt;</span> </pre></p>

   适合机器读取的时间值可能对搜索引擎、日历程序等有帮助。 
meter

meter 元素表示指定范围内的数字值。例如,可以用它表示薪水、投票给 Le Pen 的法国选民的百分比或考试分数。在这里,我使用 meter 标出 Software Development 2007 上一位 Google 程序员提供的数据:

   1: <p>An entry level programmer in Silicon Valley 
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   2:</span> can expect to start around <span style="color: #0000ff">&lt;</span><span style="color: #800000">meter</span><span style="color: #0000ff">&gt;</span>$90,000<span style="color: #0000ff">&lt;/</span><span style="color: #800000">meter</span><span style="color: #0000ff">&gt;</span> per year.</pre>

<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   3:</span> <span style="color: #0000ff">&lt;/</span><span style="color: #800000">p</span><span style="color: #0000ff">&gt;</span> </pre></p>

  meter 元素帮助浏览器和其他客户机识别 HTML 页面中的数量。它不要求对元素内容应用任何特定的格式。但是,每个 meter 元素可以有最多 6 个属性,它们按照更适合机器识别的形式表示这个数量: 
value 
min 
low 
high 
max 
optimum 
这些属性都应该包含一个十进制数字。例如,期末考试的分数可以写成下面这样:

   1: <p>Your score was 
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   2:</span> <span style="color: #0000ff">&lt;</span><span style="color: #800000">meter</span> <span style="color: #ff0000">value</span><span style="color: #0000ff">="88.7"</span> <span style="color: #ff0000">min</span><span style="color: #0000ff">="0"</span> <span style="color: #ff0000">max</span><span style="color: #0000ff">="100"</span> <span style="color: #ff0000">low</span><span style="color: #0000ff">="65"</span> <span style="color: #ff0000">high</span><span style="color: #0000ff">="96"</span> <span style="color: #ff0000">optimum</span><span style="color: #0000ff">="100"</span><span style="color: #0000ff">&gt;</span>B+<span style="color: #0000ff">&lt;/</span><span style="color: #800000">meter</span><span style="color: #0000ff">&gt;</span>.</pre>

<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   3:</span> <span style="color: #0000ff">&lt;/</span><span style="color: #800000">p</span><span style="color: #0000ff">&gt;</span> </pre></p>

   这表示这个学生的分数是百分制中的 88.7。可能的最低分数是 0,但是实际的最低分数是 65。可能的最高分数是 100,但是实际的最高分数是  96。用户代理可以用某种数值控件显示这一信息,也可以在工具提示中显示额外的数据,但是最常见的情况可能是像其他内联元素一样对它应用样式。 
progress

progress 元素表示一个正在进行的过程的状态,就像图形用户界面(GUI)应用程序中的进度条。例如,可以用它表示一个文件已经下载的百分比或者播放电影时的当前位置。下面这个进度控件表示下载已经完成了 33%:

   1: <p>Downloaded: 
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   2:</span>   <span style="color: #0000ff">&lt;</span><span style="color: #800000">progress</span> <span style="color: #ff0000">value</span><span style="color: #0000ff">="1534602"</span> <span style="color: #ff0000">max</span><span style="color: #0000ff">="4603807"</span><span style="color: #0000ff">&gt;</span>33%<span style="color: #0000ff">&lt;/</span><span style="color: #800000">progress</span><span style="color: #0000ff">&gt;</span></pre>

<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   3:</span> <span style="color: #0000ff">&lt;/</span><span style="color: #800000">p</span><span style="color: #0000ff">&gt;</span> </pre></p>

   value 属性表示操作的当前状态。max 属性表示操作的总量。这个元素指出要下载的数据总量是 4,603,807 字节,已经下载了 1,534,602 字节。 
忽略 max 属性,就可以显示无限的进度。 
在操作进行时,应该使用 JavaScript 语言动态地更新进度条。在静态情况下,这个元素没什么意义。

转载自:52CSS


最后修改于 2008-03-09