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
Release: 2024-12-19 16:31:09
Original
126 people have browsed it

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 }
Copy after login

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>
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template