ol

<ol>

HTML <ol>元素代表项目,通常呈现为编号列表的有序列表。

内容类别Flow content, and if the
    element's children include at least one
  1. element, palpable content.
允许的内容 一个或多个<li>元素。这些<li>元素可以再包含嵌套的<ol>或<ul>元素。
标签省略不允许,开始标签和结束标签都不能省略。
允许的父元素Any element that accepts flow content.
允许的 ARIA 角色directory, group, listbox, menu, menubar, radiogroup, tablist, toolbar, tree, presentation
DOM 接口HTMLOListElement

属性

这个元素包含全局属性。

compact 这个布尔属性暗示列表应该以紧凑的风格呈现。该属性的解释取决于用户代理,并且不适用于所有浏览器。

注: 不要使用这个属性,这个属性已经过时:<ol>元素的样式应当使用CSS 来控制,想要获得和这个属性相似的效果,使用 CSS 属性 line-height并设置值为 80%。

reversed HTML5 这个布尔属性规定了列表的条目采用倒序,即最不重要的条目放在列表第一个位置。

注:这个属性在 HTML4 中弃用,但是在 HTML5 中被重新引入。

type 指示编号类型:

  • 'a'表示小写字母编号,

这个类型集用于整个列表,除非type在封闭<li>元素中使用了不同的属性。

注意:此属性在 HTML4 中已被弃用,但在 HTML5 中重新引入。除非清单号码的价值很重要(例如,在法律或技术文件中的项目将通过其号码/字母引用),则list-style-type应该使用 CSS 属性。

使用说明

  • 通常,有序列表条目和它前面的编号一起显示,它的编号可以是任何形式,如数字、字母或者罗马数字,甚至可以是小子弹。而这种样式(小子弹)并没有在 HTML 页面内定义,而是在其关联的 CSS 中,使用了 list-style-type 属性。

示例

简单示例

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

在 HTML 上方输出:

  • first item

使用罗马数字类型

<ol type="i"> <li>foo</li> <li>bar</li> <li>spam</li> </ol>

上面的 HTML 将输出

i. foo

ii. bar

iii. spam

使用start属性

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

在 HTML 上方输出:

  • first item

嵌套列表

<ol> <li>first item</li> <li>second item <!-- closing </li> tag not here! --> <ol> <li>second item first subitem</li> <li>second item second subitem</li> <li>second item third subitem</li> </ol> </li> <!-- Here's the closing </li> tag --> <li>third item</li> </ol>

在 HTML 上方输出:

  • first item

嵌套 <ol> 和 <ul>

<ol> <li>first item</li> <li>second item <!-- closing </li> tag not here! --> <ul> <li>second item first subitem</li> <li>second item second subitem</li> <li>second item third subitem</li> </ul> </li> <!-- Here's the closing </li> tag --> <li>third item</li> </ol>

在 HTML 上方输出:

  • first item

规范

SpecificationStatusComment
HTML Living StandardThe definition of '<ol>' in that specification.Living StandardNo change since last W3C snapshot, HTML5.
HTML5The definition of 'HTMLOListElement' in that specification.RecommendationAdded reversed and start attributed; un-deprecated type
HTML 4.01 SpecificationThe definition of '<ol>' in that specification.RecommendationDeprecated compact and type.

浏览器兼容性

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic Support(Yes)(Yes)1(Yes)(Yes)(Yes)
compact(Yes)(Yes)1(Yes)(Yes)(Yes)
reversed18?18No(Yes)5.2
start(Yes)(Yes)1(Yes)(Yes)(Yes)
type(Yes)(Yes)1(Yes)(Yes)(Yes)

FeatureAndroidChrome for AndroidEdge mobileFirefox for AndroidIE mobileOpera AndroidiOS Safari
Basic Support(Yes)(Yes)(Yes)1(Yes)(Yes)(Yes)
compact(Yes)(Yes)(Yes)1(Yes)(Yes)(Yes)
reversed(Yes)(Yes)?18No(Yes)(Yes)
start(Yes)(Yes)(Yes)1(Yes)(Yes)(Yes)
type(Yes)(Yes)(Yes)1(Yes)(Yes)(Yes)