|
28 | 28 | align-items: flex-start; |
29 | 29 | } |
30 | 30 |
|
31 | | -/* Counter for numbered lists */ |
| 31 | +/* |
| 32 | +
|
| 33 | + Numbered List Counter System |
| 34 | + |
| 35 | + CSS counters automatically number list items: |
| 36 | + - counter-increment: Adds 1 to 'list-number' counter for each numbered list item |
| 37 | + - counter-reset: Resets 'list-number' to 0 when starting a new sequence |
| 38 | + |
| 39 | + Counter resets in two scenarios: |
| 40 | + 1. :first-child - First numbered list in any container |
| 41 | + 2. After non-list content - When numbered list follows paragraph, code, etc. |
| 42 | + |
| 43 | + Example HTML structure: |
| 44 | + <div class="page-content"> |
| 45 | + <li class="notion-numbered_list-block">Item 1</li> ← :first-child reset |
| 46 | + <li class="notion-numbered_list-block">Item 2</li> ← Continue sequence |
| 47 | + <p class="notion-paragraph-block">Text</p> ← Non-list content |
| 48 | + <li class="notion-numbered_list-block">Item 1</li> ← Adjacent sibling reset |
| 49 | + <li class="notion-numbered_list-block">Item 2</li> ← Continue sequence |
| 50 | + </div> |
| 51 | + |
| 52 | +*/ |
| 53 | + |
| 54 | +/* Increment counter for each numbered list item */ |
32 | 55 | .notion-numbered_list-block { |
33 | 56 | counter-increment: list-number 1; |
34 | 57 | } |
35 | 58 |
|
36 | | -/* Reset counter for first numbered list item or when starting a new sequence */ |
| 59 | +/* |
| 60 | + Reset counter when starting a new numbered list sequence |
| 61 | + |
| 62 | + Selector: .notion-numbered_list-block:first-child |
| 63 | + Targets: Numbered list items that are the very first element in their container |
| 64 | + |
| 65 | + Example HTML structure: |
| 66 | + <div class="page-content"> |
| 67 | + <li class="notion-numbered_list-block">Item 1</li> ← :first-child - Reset counter here |
| 68 | + <li class="notion-numbered_list-block">Item 2</li> ← Continue sequence |
| 69 | + <li class="notion-numbered_list-block">Item 3</li> ← Continue sequence |
| 70 | + </div> |
| 71 | + |
| 72 | +*/ |
37 | 73 | .notion-numbered_list-block:first-child { |
38 | 74 | counter-reset: list-number 0; |
39 | 75 | } |
40 | 76 |
|
41 | | -/* Alternative: Reset when previous sibling is not a numbered list */ |
| 77 | +/* |
| 78 | + Reset counter when numbered list follows non-list content |
| 79 | + |
| 80 | + Selector: *:not(.notion-numbered_list-block) + .notion-numbered_list-block |
| 81 | +
|
| 82 | + Breakdown: |
| 83 | + - *:not(.notion-numbered_list-block) = Any element that is NOT a numbered list item |
| 84 | + - + = Adjacent sibling combinator (immediately followed by) |
| 85 | + - .notion-numbered_list-block = A numbered list item |
| 86 | +
|
| 87 | + Example HTML structure: |
| 88 | + <div class="page-content"> |
| 89 | + <p class="notion-paragraph-block">Some text</p> |
| 90 | + <li class="notion-numbered_list-block">Item 1</li> ← Reset counter here (follows paragraph) |
| 91 | + <li class="notion-numbered_list-block">Item 2</li> ← Continue sequence |
| 92 | + <pre class="notion-code-block">Code</pre> |
| 93 | + <li class="notion-numbered_list-block">Item 1</li> ← Reset counter here (follows code) |
| 94 | + <li class="notion-numbered_list-block">Item 2</li> ← Continue sequence |
| 95 | + </div> |
| 96 | + |
| 97 | +*/ |
42 | 98 | *:not(.notion-numbered_list-block) + .notion-numbered_list-block { |
43 | 99 | counter-reset: list-number 0; |
44 | 100 | } |
|
53 | 109 | line-height: var(--jsondoc-line-height-tight); |
54 | 110 | } |
55 | 111 |
|
| 112 | +/* |
| 113 | + Display the counter value as visible numbers |
| 114 | + |
| 115 | + counter(list-number): Reads current value of 'list-number' counter and displays it |
| 116 | + counter(list-number) returns "1", "2", "3", etc. |
| 117 | + Combined with ". " to create "1. ", "2. ", "3. " format |
| 118 | + min-width + text-align: right ensures consistent alignment regardless of digit count |
| 119 | + |
| 120 | +*/ |
56 | 121 | .notion-numbered_list-block::before { |
57 | 122 | content: counter(list-number) ". "; |
58 | 123 | font-size: var(--jsondoc-font-size-body); |
|
0 commit comments