Start a list from a certain number

2019-07-17 10:52发布

问题:

What's the best way to get a ol to start from 'x'?

The start tag is deprecated and everything I have found on Google has used the :before pseudo class which doesn't work in IE6 or 7. Didn't have much luck when searching stack either.

Only thing I can think of is manually go through and number the lists myself and style accordingly?

Any help appreciated.

回答1:

While the start attribute in HTML 4 is indeed deprecated, looking at the HTML 5 docs, I see:

The start attribute, if present, must be a valid integer giving the ordinal value of the first list item.

If the start attribute is present, user agents must parse it as an integer, in order to determine the attribute's value. The default value, used if the attribute is missing or if the value cannot be converted to a number according to the referenced algorithm, is 1 if the element has no reversed attribute, and is the number of child li elements otherwise.

The first item in the list has the ordinal value given by the ol element's start attribute, unless that li element has a value attribute with a value that can be successfully parsed, in which case it has the ordinal value given by that value attribute.

which tells me I am safe using start with ol and value with li elements.



回答2:

With ordered lists ol, you could use the various counter CSS instructions: Examples here. But, they also won't work with IE6 and 7. I don't think there is a non-Javascript way to make this work in them.