Recently I ran into a problem where I have created an ordered list with more than hundred list items. I have set list-style: decimal-leading-zero;
ol{
list-style: decimal-leading-zero;
}
<ol>
<li>Some item</li>
<li>Some item</li>
<li>Some item</li>
<li>Some item</li>
<li>Some item</li>
<li>Some item</li>
<li>Some item</li>
<li>Some item</li>
<li>Some item</li>
<li>Some item</li>
<li>Some item</li>
<li>Some item</li>
</ol>
<p>...</p>
<ol start="96">
<li>Some item</li>
<li>Some item</li>
<li>Some item</li>
<li>Some item</li>
<li>Some item</li>
<li>Some item</li>
<li>Some item</li>
<li>Some item</li>
<li>Some item</li>
<li>Some item</li>
<li>Some item</li>
<li>Some item</li>
</ol>
Issue: Only first nine list items have leading zero.
Extpected: two leading zeros in first nine list items and one leading zero for 10th to 99th list items.
There is no list-style
for three digit decimals.
However, you can use pseudo-selectors and counters to achieve what you want here.
Refer 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)". ";
}
<ol>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
<li>Item 5</li>
<li>Item 6</li>
<li>Item 7</li>
<li>Item 8</li>
<li>Item 9</li>
<li>Item 10</li>
<li>Item 11</li>
<li>Item 12</li>
<li>Item 13</li>
<li>Item 14</li>
<li>Item 15</li>
<li>Item 16</li>
<li>Item 17</li>
<li>Item 18</li>
<li>Item 19</li>
<li>Item 20</li>
<li>Item 21</li>
<li>Item 22</li>
<li>Item 23</li>
<li>Item 24</li>
<li>Item 25</li>
<li>Item 26</li>
<li>Item 27</li>
<li>Item 28</li>
<li>Item 29</li>
<li>Item 30</li>
<li>Item 31</li>
<li>Item 32</li>
<li>Item 33</li>
<li>Item 34</li>
<li>Item 35</li>
<li>Item 36</li>
<li>Item 37</li>
<li>Item 38</li>
<li>Item 39</li>
<li>Item 40</li>
<li>Item 41</li>
<li>Item 42</li>
<li>Item 43</li>
<li>Item 44</li>
<li>Item 45</li>
<li>Item 46</li>
<li>Item 47</li>
<li>Item 48</li>
<li>Item 49</li>
<li>Item 50</li>
<li>Item 51</li>
<li>Item 52</li>
<li>Item 53</li>
<li>Item 54</li>
<li>Item 55</li>
<li>Item 56</li>
<li>Item 57</li>
<li>Item 58</li>
<li>Item 59</li>
<li>Item 60</li>
<li>Item 61</li>
<li>Item 62</li>
<li>Item 63</li>
<li>Item 64</li>
<li>Item 65</li>
<li>Item 66</li>
<li>Item 67</li>
<li>Item 68</li>
<li>Item 69</li>
<li>Item 70</li>
<li>Item 71</li>
<li>Item 72</li>
<li>Item 73</li>
<li>Item 74</li>
<li>Item 75</li>
<li>Item 76</li>
<li>Item 77</li>
<li>Item 78</li>
<li>Item 79</li>
<li>Item 80</li>
<li>Item 81</li>
<li>Item 82</li>
<li>Item 83</li>
<li>Item 84</li>
<li>Item 85</li>
<li>Item 86</li>
<li>Item 87</li>
<li>Item 88</li>
<li>Item 89</li>
<li>Item 90</li>
<li>Item 91</li>
<li>Item 92</li>
<li>Item 93</li>
<li>Item 94</li>
<li>Item 95</li>
<li>Item 96</li>
<li>Item 97</li>
<li>Item 98</li>
<li>Item 99</li>
<li>Item 100</li>
<li>Item 101</li>
<li>Item 102</li>
</ol>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With