Please note, this is a STATIC archive of website developer.mozilla.org from November 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

<ol>

这篇翻译不完整。请帮忙从英语翻译这篇文章

HTML <ol> 元素 (或者 HTML 有序列表 Element) 表示多个有序列表项。通常情况下,有序列表中显示在项前面的编号(a preceding numbering),可以是任何形式的,如数字,字母或罗马数字甚至简单的点。 在网页的 HTML 描述中并没有定义编号的样式,但可以用相关的CSS定义,使用 list-style-type 属性。

HTML 并没有对 <ol><ul> 元素的深度和反复使用次数(overlap)作出限制。

注意: <ol><ul> 都是列表项。它们的微妙区别是在 <ol> 元素里顺序是有意义多。 对于该选择哪一个去使用下面有个建议:尝试去更改列表项的顺序;如果其含义改变里,那么应该使用 <ol> 元素,否则使用 <ul>
  • 内容分类Flow content, and if the <ol> element's children include at least one <li> element, palpable content.
  • 允许的内容 Zero or more <li> elements
  • 标签省略 不允许,开始标签和结束标签都不能省略。
  • 允许的父元素 Any element that accepts flow content.
  • DOM 接口 HTMLOListElement

Attributes

这个元素包含 全局属性.

compact
This Boolean attribute hints that the list should be rendered in a compact style. The interpretation of this attribute depends on the user agent and it doesn't work in all browsers.
Note: Do not use this attribute, as it has been deprecated: the <ol> element should be styled using CSS. To give an effect similar to the compact attribute, the CSS property line-height can be used with a value of 80%.
reversed HTML5
这个布尔属性规定了列表的条目采用倒序,即最不重要的条目放在列表第一个位置。
startHTML5
This integer attribute specifies the start value for numbering the individual list items. Although the ordering type of list elements might be Roman numerals, such as XXXI, or letters, the value of start is always represented as a number. To start numbering elements from the letter "C", use <ol start="3">.
Note: 这个属性在 HTML4中弃用,但是在 HTML5 中被重新引入。
type
Indicates the numbering type:
  • 'a' indicates lowercase letters,
  • 'A' indicates uppercase letters,
  • 'i' indicates lowercase Roman numerals,
  • 'I' indicates uppercase Roman numerals,
  • and '1' indicates numbers (default).

The type set is used for the entire list unless a different type attribute is used within an enclosed <li> element.

Note: This attribute was deprecated in HTML4, but reintroduced in HTML5. Unless the value of the list number matters (e.g. in legal or technical documents where items are to be referenced by their number/letter), the CSS list-style-type property should be used instead.

示例

简单示例

<ol>
  <li>first item</li>
  <li>second item</li>
  <li>third item</li>
</ol>

以上 HTML 输出如下:

  1. first item
  2. second item
  3. third item

使用 start 属性

<ol start="7">
  <li>first item</li>
  <li>second item</li>
  <li>third item</li>
</ol>

以上 HTML 输出如下:

  1. first item
  2. second item
  3. third item

嵌套列表

<ol>
  <li>first item</li>
  <li>second item      <!-- Look, the closing </li> tag is not placed here! -->
    <ol>
      <li>second item first subitem</li>
      <li>second item second subitem</li>
      <li>second item third subitem</li>
    </ol>
  </li>                <!-- Here is the closing </li> tag -->
  <li>third item</li>
</ol>

以上 HTML 输出如下:

  1. first item
  2. second item
    1. second item first subitem
    2. second item second subitem
    3. second item third subitem
  3. third item

Nested <ol> and <ul>

<ol>
  <li>first item</li>
  <li>second item      <!-- Look, the closing </li> tag is not placed here! -->
    <ul>
      <li>second item first subitem</li>
      <li>second item second subitem</li>
      <li>second item third subitem</li>
    </ul>
  </li>                <!-- Here is the closing </li> tag -->
  <li>third item</li>
</ol>

以上 HTML 输出如下:

  1. first item
  2. second item
    • second item first subitem
    • second item second subitem
    • second item third subitem
  3. third item

规范

Specification Status Comment
WHATWG HTML Living Standard
<ol>
Living Standard  
HTML5
HTMLOListElement
Recommendation  
HTML 4.01 Specification
<ol>
Recommendation  

浏览器兼容性

特性 Chrome Firefox (Gecko) Internet Explorer Opera Safari
基础支持 1.0 1.0 (1.7 or earlier) 1.0 1.0 1.0
reversed 属性 18 18.0 (18.0) 未实现 未实现 5.2
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) 1.0 (1.0) (Yes) (Yes) (Yes)
reversed attribute (Yes) 18.0 (18.0) 未实现 未实现 (Yes)

相关

  • 其他列表相关的 HTML 元素: <ul>, <li>, <menu> and the obsolete <dir>;
  • CSS properties that may be specially useful to style the <ol> element:
    • the list-style property, useful to choose the way the ordinal is displayed,
    • CSS counters, useful to handle complex nested lists,
    • the line-height property, useful to simulate the deprecated compact attribute,
    • the margin property, useful to control the indent of the list.

文档标签和贡献者

 此页面的贡献者: tcatche, Ende93, dongnanzhan, FredWe
 最后编辑者: tcatche,