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:

Decoupling Monoliths Into Microservices With Feature Flags

Decoupling monoliths into microservices with feature flags

Explore how to effectively break down a monolithic application into microservices using feature flags and Flagsmith.

Kayode Adeniyi
Jul 25, 2024 â‹… 10 min read
Lots of multi-colored blue and purplish rectangles.

Animating dialog and popover elements with CSS @starting-style

Native dialog and popover elements have their own well-defined roles in modern-day frontend web development. Dialog elements are known to […]

Rahul Chhodde
Jul 24, 2024 â‹… 10 min read
Using Llama Index To Add Personal Data To Large Language Models

Using LlamaIndex to add personal data to LLMs

LlamaIndex provides tools for ingesting, processing, and implementing complex query workflows that combine data access with LLM prompting.

Ukeje Goodness
Jul 23, 2024 â‹… 5 min read
JavaScript logo on top of violet background

Exploring essential DOM methods for frontend development

Learn four groups of DOM methods and their uses to create responsive and dynamic webpages. A helpful DOM reference table is also included.

Chimezie Innocent
Jul 23, 2024 â‹… 12 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