2020-05-12
1292
#css
Supun Kavinda
18360
May 12, 2020 â‹… 4 min read

Styling numbered lists with CSS counters

Supun Kavinda I started as a self-taught PHP developer before creating my own company, Hyvor. I am particularly interested in physics and machine learning.

Recent posts:

Comparing Hattip Vs Express Js For Modern Application Development

Comparing Hattip vs. Express.js for modern app development

Explore what Hattip is, how it works, its benefits and key features, and the differences between Hattip and Express.js.

Antonello Zanini
May 2, 2024 â‹… 8 min read
Using React Shepherd To Build A Site Tour

Using React Shepherd to build a site tour

React Shepherd stands out as a site tour library due to its elegant UI and out-of-the-box, easy-to-use React Context implementation.

Onuorah Bonaventure
May 1, 2024 â‹… 14 min read
A Guide To Cookies In Next Js

A guide to cookies in Next.js

Cookies are crucial to web development. This article will explore how to handle cookies in your Next.js applications.

Georgey V B
Apr 30, 2024 â‹… 10 min read
Handling Dates In JavaScript With Tempo

Handling dates in JavaScript with Tempo

Use the Tempo library to format dates and times in JavaScript while accounting for time zones, daylight saying time, and date internationalization.

Amazing Enyichi Agu
Apr 30, 2024 â‹… 8 min read
View all posts

4 Replies to "Styling numbered lists with CSS counters"

  1. You cannot just get rid of semantics and splash divs everywhere nilly-willy. That’s not how HTML works.

  2. One of the problems here is getting everything to line up nicely and work when using paragraphs that wrap in smaller screens. Solution: Apply the before pseudo class to a span element as follows:
    The thinking is done for you. You don’t have to worry about logistics at all.
    Wrap the li content in a div to be able to apply top padding if preferred:

    ol.numbered-list {
    display: flex;
    flex-wrap: wrap;
    margin: 0;
    padding: 0;
    list-style: none;
    counter-reset: list-number;
    }
    ol.numbered-list li {
    counter-increment: list-number;
    margin-bottom: 7px;
    display: flex;
    width: 90%;
    vertical-align: middle;
    }

    ol.numbered-list span {
    display: inline-block;
    vertical-align: middle;
    }
    ol.numbered-list div {
    display: inline-block;
    vertical-align: middle;
    padding-top: 4px;
    }

    ol.numbered-list li span:before {
    content: counter(list-number);

    margin-right: 10px;
    background-color: #0191C8;
    border-radius: 50%;
    color: #FFF;
    width: 2rem;
    height: 2rem;
    padding-top: 0.3rem;
    display: inline-block;
    text-align: center;
    font-size: 16px;
    box-sizing: border-box;
    }

Leave a Reply