在前端开发中,HTML 为我们提供了丰富的标签来组织和展示内容,有序列表就是其中一种非常实用的方式。有序列表使用 <ol>
标签来创建,它会按照一定的顺序对列表项进行编号。<ol>
标签有一个很重要的属性 type
,通过这个属性,我们可以指定有序列表的编号类型。下面就来详细介绍一下 <ol>
标签中 type
属性的各种取值。
type="1"
(默认值)当 type
属性的值为 1
时,列表项会以阿拉伯数字 1, 2, 3...
进行编号,这也是 <ol>
标签的默认编号方式。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ordered List - Type 1</title>
</head>
<body>
<ol type="1">
<li>苹果</li>
<li>香蕉</li>
<li>橙子</li>
</ol>
</body>
</html>
type="A"
当 type
属性的值为 A
时,列表项会以大写英文字母 A, B, C...
进行编号。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ordered List - Type A</title>
</head>
<body>
<ol type="A">
<li>红色</li>
<li>蓝色</li>
<li>绿色</li>
</ol>
</body>
</html>
A. 红色
B. 蓝色
C. 绿色
type="a"
当 type
属性的值为 a
时,列表项会以小写英文字母 a, b, c...
进行编号。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ordered List - Type a</title>
</head>
<body>
<ol type="a">
<li>星期一</li>
<li>星期二</li>
<li>星期三</li>
</ol>
</body>
</html>
a. 星期一
b. 星期二
c. 星期三
type="I"
当 type
属性的值为 I
时,列表项会以大写罗马数字 I, II, III...
进行编号。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ordered List - Type I</title>
</head>
<body>
<ol type="I">
<li>第一章</li>
<li>第二章</li>
<li>第三章</li>
</ol>
</body>
</html>
I. 第一章
II. 第二章
III. 第三章
type="i"
当 type
属性的值为 i
时,列表项会以小写罗马数字 i, ii, iii...
进行编号。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ordered List - Type i</title>
</head>
<body>
<ol type="i">
<li>第一节</li>
<li>第二节</li>
<li>第三节</li>
</ol>
</body>
</html>
i. 第一节
ii. 第二节
iii. 第三节
type 属性值 |
编号类型 | 示例 |
---|---|---|
1 |
阿拉伯数字 | 1, 2, 3… |
A |
大写英文字母 | A, B, C… |
a |
小写英文字母 | a, b, c… |
I |
大写罗马数字 | I, II, III… |
i |
小写罗马数字 | i, ii, iii… |
通过合理使用 <ol>
标签的 type
属性,我们可以根据不同的需求选择合适的编号类型,使网页内容的展示更加清晰和有条理。在实际开发中,我们可以根据文档的结构和风格来灵活运用这些编号类型,让用户能够更轻松地理解和阅读网页内容。