CSS leading zeros for decimals not working with large numbers
P粉018548441
P粉018548441 2023-11-07 10:35:53
0
1
605

I recently encountered a problem where I created an ordered list containing over a hundred list items. I setlist-style:decimal-leading-zero;

ol{ list-style: decimal-leading-zero; }
  1. Some item
  2. Some item
  3. Some item
  4. Some item
  5. Some item
  6. Some item
  7. Some item
  8. Some item
  9. Some item
  10. Some item
  11. Some item
  12. Some item

...

  1. Some item
  2. Some item
  3. Some item
  4. Some item
  5. Some item
  6. Some item
  7. Some item
  8. Some item
  9. Some item
  10. Some item
  11. Some item
  12. Some item

Problem:Only the first nine list items have leading zeros.

Expected:Two leading zeros in the first nine list items, and one leading zero in the 10th to 99th list items.

P粉018548441
P粉018548441

reply all (1)
P粉576184933

There is nolist-stylefor three decimal places.

However, you can use pseudo-selectors andcounters a> to achieve what you want here.

Reference Code:

ol { counter-reset: items; } li { display: block; counter-increment: items; } li:before { content: "00" counter(items)". "; } li:nth-child(n+10):before { content: "0" counter(items)". "; } li:nth-child(n+100):before { content: counter(items)". "; }
  1. Item 1
  2. Item 2
  3. Item 3
  4. Item 4
  5. Item 5
  6. Item 6
  7. Item 7
  8. Item 8
  9. Item 9
  10. Item 10
  11. Item 11
  12. Item 12
  13. Item 13
  14. Item 14
  15. Item 15
  16. Item 16
  17. Item 17
  18. Item 18
  19. Item 19
  20. Item 20
  21. Item 21
  22. Item 22
  23. Item 23
  24. Item 24
  25. Item 25
  26. Item 26
  27. Item 27
  28. Item 28
  29. Item 29
  30. Item 30
  31. Item 31
  32. Item 32
  33. Item 33
  34. Item 34
  35. Item 35
  36. Item 36
  37. Item 37
  38. Item 38
  39. Item 39
  40. Item 40
  41. Item 41
  42. Item 42
  43. Item 43
  44. Item 44
  45. Item 45
  46. Item 46
  47. Item 47
  48. Item 48
  49. Item 49
  50. Item 50
  51. Item 51
  52. Item 52
  53. Item 53
  54. Item 54
  55. Item 55
  56. Item 56
  57. Item 57
  58. Item 58
  59. Item 59
  60. Item 60
  61. Item 61
  62. Item 62
  63. Item 63
  64. Item 64
  65. Item 65
  66. Item 66
  67. Item 67
  68. Item 68
  69. Item 69
  70. Item 70
  71. Item 71
  72. Item 72
  73. Item 73
  74. Item 74
  75. Item 75
  76. Item 76
  77. Item 77
  78. Item 78
  79. Item 79
  80. Item 80
  81. Item 81
  82. Item 82
  83. Item 83
  84. Item 84
  85. Item 85
  86. Item 86
  87. Item 87
  88. Item 88
  89. Item 89
  90. Item 90
  91. Item 91
  92. Item 92
  93. Item 93
  94. Item 94
  95. Item 95
  96. Item 96
  97. Item 97
  98. Item 98
  99. Item 99
  100. Item 100
  101. Item 101
  102. Item 102
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!