• How does one add something as a dot after a counter inside a content property in TailwindCSS?

    372 views Asked by At

    I have this numbered list (I have omitted the counter-reset and counter-increment for legibility):

    <ol class="...">
        <li class="... before:content-[counter(name)]">I like cheese</li>
    </ol>
    

    which results in

    1I like cheese

    I would like to add a period and a space after the counter, so it becomes:

    1. I like cheese

    but the framework won't let me parse something that normally would work in vanilla CSS:

    content: counter(name) '. ';
    

    How do I work around this without having to add a hard-coded class myself? Or perhaps, is there a proper way of handling this, by making a particular plugin that would accept a similar value?

    Edit: I now realize there indeed is something as list-decimal which exactly does this too, but I am specifically curious about a working alternative if one would still use a CSS-counter in a before.

    2

    There are 2 answers

    1
    Eren On
    <ol class="list-decimal list-inside">
      <li>item</li>
      <li>item</li>
      <li>item</li>
      <li>item</li>
    </ol>
    

    i think this is what you are trying to do.

    https://flowbite.com/docs/typography/lists/

    0
    anry_iron On

    try this syntax class="[content:counters(section'.')]". without a comma after 'section'. But it will break lists counting inside, and will start from 1, 2, 3...