更改有序列表上的编号? [英] Change the numbering on an ordered list?

查看:253
本文介绍了更改有序列表上的编号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您可以更改有序列表的启动次数,如下所示:

You can change the number at which an ordered list starts like this:

<ol start="3">
    <li>item three</li>
    <li>item four</li>
</ol>

...但是有没有办法使列表项具有任意数字,而不只是连续编号?

...but is there a way to make list items have arbitrary numbers, not just consecutive numbering?

<ol>
    <li>item two</li>
    <li>item six</li>
    <li>item nine</li>
</ol>

我现在可以看到的唯一方法是将每个 ; li> 在其自己的< ol> 中,这显然是不理想的。欢迎使用HTML,Javascript和CSS解决方案。

The only way I can see to do it now is to wrap each <li> in its own <ol> which obviously isn't ideal. HTML, Javascript and CSS solutions are welcome.

ps:虽然项目编号是任意的,但它们仍然是有序的,因此不要担心语义

推荐答案

HTML 4.01 < li> 上存在已弃用的 code>:

In HTML 4.01 there is a deprecated value attribute on <li> :

<ol>
<li value="30"> makes this list item number 30.
<li value="40"> makes this list item number 40.
<li> makes this list item number 41.
</ol>

非弃用(CSS)答案直接:) 规范有点干燥; googling会显示更多可立即使用的内容,例如

The non-deprecated (CSS) answer is (as so often) more elegant but less... direct :) The spec is somewhat dry; googling turns up more immediately usable stuff such as this :


就像从上一个列表中继续编号
一样,
设置CSS属性以增加
正确的计数器。但是要使它
开始从不同的
开始递增你可以传递
可选的第二个参数
计数器复位属性的一个数字。所以
从5开始会在你的CSS中看起来像这样的

Just like continuing the numbering from the previous list you’ll need to set the CSS property for incrementing the proper counter. But to make it start incrementing from a different starting point you can pass an optional second parameter in counter-reset property of a number. So starting from 5 would look something like this in your CSS:

ol.continue {
  counter-reset: chapter 4;     /* Resets counter to 4. */
}


在它递增之前,开始我们的
列表,数字为5,我们将把
设置为4。

Since the counter will always be reset before it is incremented, to start our list with the number 5 we will have to set the counter to 4.

这篇关于更改有序列表上的编号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆