January 26, 2024
If you've ever attempted to create a layout similar to what my website has (assuming you're reading this on desktop), you may have encountered a problem where a Flexbox child, instead of fitting perfectly inside its parent, grows so big that the parent's width also expands, even if a fixed width is set.
Here is a simplified view of what's happening:
The blog is rendered inside the red box, and in the screenshot above, you can observe that the blog is overflowing, causing the entire page to have a horizontal layout. The overflow in the blog is due to a code block with a pre tag containing a very long line of code that extends beyond the page.
One might assume that simply adding
overflow-x: auto
width: 100%
I've created a CodePen example for you to waste you precious time on this stupid bug: CodePen Example
I've already added
overflow: auto
In addition to adding
overflow: auto
overflow: auto
Try adding
overflow-auto
.child-3
Explanation: I don't know; it's just how CSS works. Adding
overflow: auto
overflow: auto