fix: extend code block background when scrolling horizontally#143
fix: extend code block background when scrolling horizontally#143janraasch merged 2 commits intojanraasch:masterfrom
Conversation
Set min-width: 100% and width: max-content on .highlight pre and .code pre so the background fills the container for short content and expands to cover long lines when scrolling horizontally. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR adjusts the theme’s code block CSS so the syntax-highlighted <pre> element expands to the full scrollable width, ensuring the background color from Hugo/Chroma remains visible when horizontally scrolling on narrow viewports.
Changes:
- Add
min-width: 100%andwidth: max-contentto.highlight preand.code preto keep code block backgrounds covering both short and long content while allowing horizontal overflow scrolling.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Hi @dbrennand, nice to meet you. Thanks so much for the pr 🤝. Very good description!!! One question: Could you point me to the blog post where you exhibited this issue or provide a code block for me to reproduce the issue on the example site? Thank you 👋 |
https://dbren.uk/blog/powershell-storing-credentials/ The first code block. |
janraasch
left a comment
There was a problem hiding this comment.
Hi @dbrennand, nice to meet you (again) 😄. I see you also worked on #126 — awesome to see you back! Thank you for your help ❤️.
Great description on this one, too!!!
Some context / history for anyone following along:
This all stems from us relying on Hugo's rendering of CSS for code blocks (see Hugo docs on Syntax Highlighting.
- In #49 we added
overflow-x: autoto handle long code lines spilling off-screen. This is exact issue 😅. - In #126 we removed our custom
colorandbackground-colorstyles fromcodeand.highlight— so people could easily customize their highlight theme inhugo.tomlwithout us interfering. - But that introduced this gap (back): when scrolling horizontally, the
<pre>background (set by Hugo's Chroma inline styles) doesn't extend, leaving a transparent/white area.
Why this fix works:
width: max-content lets <pre> grow for long lines. min-width: 100% ensures the <pre> still fills the container for short content. The browser resolves to max(min-width, width), covering both cases. Simple and clean 👌.
Alternative considered:
Another approach would have been to use Hugo's CSS class mode (noClasses = false) and then add the background-color from <pre> to .highlight ourselves. But that'd make using this theme just a tidbit too complicated, since users would need to run hugo gen chromastyles to generate a stylesheet and then add this to their page. So we're not going that route.
➡️ With this we start to interfere a little bit again with Hugo's highlight styling, but I think it's a good trade-off. Let's see how it goes 🤝.
Merging this puppy — thank you @dbrennand 🙏!

Summary
min-width: 100%; width: max-contentto.highlight preand.code preProblem
On small screens, when a code block contains a line longer than the viewport width, Hugo's chroma highlighter sets a background color on the
<pre>element. Withoverflow-x: autoon.highlight, the scrollable area is created — but the<pre>only fills the visible container width. Scrolling right reveals text on a transparent/white background.Fix
min-width: 100%ensures the<pre>always fills the container for short content.width: max-contentallows it to grow beyond the container for long lines. The browser resolves tomax(min-width, width), handling both cases correctly.🤖 Generated with Claude Code