Home >Web Front-end >CSS Tutorial >Can CSS Counters Create Numbered Lists with Decimal Points?

Can CSS Counters Create Numbered Lists with Decimal Points?

Susan Sarandon
Susan SarandonOriginal
2024-12-19 16:31:09187browse

Can CSS Counters Create Numbered Lists with Decimal Points?

Creating Numbered Lists with Decimal Points

Can CSS be used to generate numbered lists with decimal points, such as 1.1, 1.2, and 1.3, rather than just 1, 2, and 3? Applying list-style-type:decimal only produces the latter sequence.

Solution: Utilizing Counters

To achieve the desired result, counters can be employed:

OL { counter-reset: item }
LI { display: block }
LI:before { content: counters(item, ".") " "; counter-increment: item }

This CSS style sheet assigns each nested list item a number with decimal points. For instance, "1", "1.1", "1.1.1", and so on.

Example:

<ol>
  <li>li element
    <ol>
      <li>sub li element</li>
      <li>sub li element</li>
      <li>sub li element</li>
    </ol>
  </li>
  <li>li element</li>
  <li>li element
    <ol>
      <li>sub li element</li>
      <li>sub li element</li>
      <li>sub li element</li>
    </ol>
  </li>
</ol>

The above is the detailed content of Can CSS Counters Create Numbered Lists with Decimal Points?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn