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 Mutative Vs Immer Vs Reducers For Data Handling In React

Comparing React state tools: Mutative vs. Immer vs. reducers

Mutative processes data with better performance than both Immer and native reducers. Let’s compare these data handling options in React.

Rashedul Alam
Apr 26, 2024 â‹… 7 min read
Radix Ui Adoption Guide Overview Examples And Alternatives

Radix UI adoption guide: Overview, examples, and alternatives

Radix UI is quickly rising in popularity and has become an excellent go-to solution for building modern design systems and websites.

Nefe Emadamerho-Atori
Apr 25, 2024 â‹… 11 min read
Understanding The Css Revert Layer Keyword, Part Of Css Cascade Layers

Understanding the CSS revert-layer keyword

In this article, we’ll explore CSS cascade layers — and, specifically, the revert-layer keyword — to help you refine your styling strategy.

Chimezie Innocent
Apr 24, 2024 â‹… 6 min read
Exploring Nushell, A Rust Powered, Cross Platform Shell

Exploring Nushell, a Rust-powered, cross-platform shell

Nushell is a modern, performant, extensible shell built with Rust. Explore its pros, cons, and how to install and get started with it.

Oduah Chigozie
Apr 23, 2024 â‹… 6 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