Nested css counters with leading zeros
Asked Answered
A

1

19

Is it possible to combine the css counters() function with leading zeros, producing a list such as this:

Item 01
  Item 01.01
  Item 01.02
    Item 01.02.01

Leading zeros are possible using content: counter(name, decimal-leading-zero), and combining nested counters is possible using content: counters(name, ".").

I know of workarounds if the level of nesting is known (i.e. I know the list will only ever nest 3 levels deep), but does anyone know if it's possible to combine these for lists of an unknown level of nesting?

Alkyl answered 7/6, 2012 at 16:30 Comment(0)
U
40

Yes, you can combine these — just supply the counter style as the last argument to counters():

content: counters(name, ".", decimal-leading-zero)
Underpainting answered 7/6, 2012 at 17:2 Comment(3)
That's great, I had been staring at the spec for a while and just couldn't see it, thanks! Edit found it now.Alkyl
Could one control the number of leading zeros or total number of digits? Similar to fprintf()?Outgoing
@Royi: I don't think you can with just counters() but maybe a custom counter style can.Underpainting

© 2022 - 2024 — McMap. All rights reserved.