Repository navigation
fix: stop the code boxes growing a vertical scrollbar - #204
Merged
Merged
Conversation
The wider snippets showed a vertical scrollbar they had no use for. Two causes, both from overflow nobody quite wrote: Astro ships the <pre> with an inline overflow-x:auto of its own, so the overflow-x:auto on .code-snippet-code made the code boxes two nested scroll containers. And neither one states overflow-y, so per the CSS overflow spec the initial `visible` is promoted to `auto` alongside a non-visible x. The horizontal scrollbar is then laid out inside the box and steals just enough height to trip the vertical one. So: drop the outer scroller and let the <pre> be the only one, state overflow-y:hidden on it, and move the bottom padding from the div onto the <pre> so the horizontal scrollbar has somewhere to sit that is not the last line of code. Bottom spacing is unchanged when no scrollbar is present. Keeping the scroller on the <pre> rather than the div is also the nicer of the two: the side padding stays a fixed gutter instead of the left one scrolling away and the code running flush to the edge. Side padding is also trimmed from 1em 1.75em to 0.9em 1.6em. Note this only reproduces where scrollbars take layout space - macOS overlay scrollbars occupy none, so it needs "Show scroll bars: Always", or Windows/Linux. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The wider snippets showed a vertical scrollbar they had no use for. Two causes, both from overflow nobody quite wrote.
What was happening
Astro ships the
<pre>with an inlineoverflow-x: autoof its own:So the code boxes were two nested scroll containers, the outer one redundant. And neither states
overflow-y, so per the CSS overflow spec the initialvisibleis promoted toautowhen the other axis is not visible. The horizontal scrollbar is then laid out inside the box and steals just enough height to trip the vertical one.That is why it was only some boxes — it tracks the ones wide enough to scroll horizontally. At 12px Monaco inside a
col-md-6, roughly:httpExampleThe fix
<pre>be the only one.overflow-y: hiddenon it, since leaving it implicit is what created the second axis.<pre>, so the horizontal scrollbar has somewhere to sit that isn't the last line of code.overflow-y: hiddenon its own would have traded the stray scrollbar for a clipped last line.Bottom spacing is unchanged when no scrollbar is present. Keeping the scroller on the
<pre>rather than the div is also the nicer of the two: the side padding stays a fixed gutter, instead of the left one scrolling away and the code running flush to the edge when you scroll right.Side padding is also trimmed from
1em 1.75emto0.9em 1.6em, as discussed separately.Reviewing it
This only reproduces where scrollbars take layout space — macOS overlay scrollbars occupy none, so you need System Settings → Appearance → Show scroll bars: Always, or Windows/Linux. Good places to look are
httpExampleat ~1280px, or most of the home page around ~1024px: the horizontal bar should sit in the padding with the last code line fully visible, and no vertical bar.npm run buildpasses; all 10 pages generate.🤖 Generated with Claude Code