Skip to content

code-tabs: keep the block in place when the tab changes - #45

Merged
ewels merged 1 commit into
mainfrom
fix/code-tabs-jump
Nov 18, 2026
Merged

ewels merged 1 commit into
mainfrom
fix/code-tabs-jump

Conversation

@ewels

@ewels ewels commented Nov 18, 2026

Copy link
Copy Markdown
Owner

Fixes #26.

  • Cause
    • Starlight's content styles give every element after a sibling a top margin (--sl-content-gap-y, 1rem), even when that sibling is hidden.
    • Code tabs render each variant as its own .expressive-code block inside [data-scb-code-tabs], and hide all but the selected one. So the first tab had no top margin and every other tab had 1rem, and the block moved down when you switched away from the first tab.
    • This affected every code tabs group on Starlight sites, not only the home page carousel. Sites without Starlight do not have the rule.
  • Fix
    • One rule in the code tabs base styles: [data-scb-code-tabs] > .expressive-code { margin-top: 0 }. It is outside any cascade layer, so it overrides Starlight's layered rule.
    • An extra wrapper div per variant would not help (the wrappers become siblings), and not-content on the group would turn off Starlight's other content styles inside the blocks.
  • Tests
    • New Playwright test: the block's top stays the same after selecting each tab, on desktop and phone.
    • pnpm test, pnpm lint and pnpm lint:docs pass.

🤖 Generated with Claude Code

Starlight gives each block after a sibling a top margin, also when the sibling is hidden, so every tab but the first moved the block down by 1rem.

Fixes #26

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ewels
ewels merged commit ae6a5a9 into main Nov 18, 2026
6 checks passed
@ewels
ewels deleted the fix/code-tabs-jump branch November 18, 2026 08:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

code blocks with with code tabs should be anchored on top

1 participant