Skip to content

Commit ec70630

Browse files
itrewdelucis
andauthored
Add bottom margin to nested lists (#3862)
Co-authored-by: Chris Swithinbank <swithinbank@gmail.com>
1 parent c73b99c commit ec70630

2 files changed

Lines changed: 28 additions & 23 deletions

File tree

.changeset/fluffy-plums-dress.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@astrojs/starlight': minor
3+
---
4+
5+
Makes spacing of items in nested lists more consistent

packages/starlight/style/markdown.css

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,31 +31,31 @@
3131
overflow-wrap: anywhere;
3232
}
3333

34+
/*
35+
* This complex selector manages spacing inside lists.
36+
*
37+
* - Finds all lists containing items with non-inline direct children (e.g.
38+
* ul > li > p)
39+
* - Applies a bottom margin to the last non-inline child of each list item
40+
* in this list
41+
*
42+
* This ensures that even if only one list item contains a block element
43+
* (most commonly a paragraph), siblings of that list item are spaced
44+
* consistently.
45+
*/
3446
.sl-markdown-content
35-
li
36-
> :is(
37-
:last-child:not(
38-
li,
39-
ul,
40-
ol,
41-
a,
42-
strong,
43-
em,
44-
del,
45-
span,
46-
input,
47-
code,
48-
br,
49-
script,
50-
:where(.not-content *)
51-
),
52-
/**
53-
* For list items ending with 1 or multiple script elements (`:has(~ script:last-child)`), we
54-
* need to style the last non-script element (`:not(script)`) that doesn't have a subsequent
55-
* sibling that is not a script (`:not(:has(~ :not(script)))`).
47+
:is(ol, ul):has(> li > :not(a, strong, em, del, span, input, code, br, script, ol, ul))
48+
> li
49+
> :is(
50+
:last-child:not(a, strong, em, del, span, input, code, br, script, :where(.not-content *)),
51+
/*
52+
* For list items ending with 1 or multiple script elements (`:has(~
53+
* script:last-child)`), we need to style the last non-script
54+
* element (`:not(script)`) that doesn't have a subsequent sibling
55+
* that is not a script (`:not(:has(~ :not(script)))`).
5656
*/
57-
:not(script):has(~ script:last-child):not(:has(~ :not(script)))
58-
) {
57+
:not(script):has(~ script:last-child):not(:has(~ :not(script)))
58+
) {
5959
margin-bottom: 1.25rem;
6060
}
6161

0 commit comments

Comments
 (0)