Una Kravets, co-host, discusses overflowing content on web pages, flex layout issues, addressing overflowing elements with CSS techniques and tools, understanding how transforms cause overflow, the importance of max width and max height, and useful DevTools tips for troubleshooting overflow problems.
Code snippets with white-space: nowrap or white-space: pre can cause horizontal scrolling, but using white-space: pre-wrap or changing width behavior can address this issue.
When using display: flex, set flex-wrap to wrap and use flex-basis to allow shrinking or growing of items to avoid overflow issues.
Deep dives
Managing Overflow in Code Snippets
One common challenge is dealing with embedded code snippets that cause horizontal scrolling on the page. Code snippets often have pre and code tags with white-space: nowrap or white-space: pre, which make the text wider than the viewport. To address this, you can apply white-space: pre-wrap to force wrapping, or allow the element to shrink and display a scroll bar by changing its width behavior. When pre tags are inside a flex container, you may need to add a minimum width or minimum inline size to make them shrink beyond their minimum content size.
Troubleshoot Flexbox Layout Overflow
When using display: flex, you might encounter overflow issues when adding a new item that doesn't fit within the container. By default, flex items do not wrap, so you need to explicitly set flex-wrap to wrap. Additionally, if the flex items are set to not shrink, they will not make room for the new item. To address this, you can use flex-basis to set an optimal size that allows shrinking or growing of items. It's important to understand the behavior of different layout models and be aware of how changes can affect the flow and sizing of elements.
Resolving Horizontal Overflow Issues
Dealing with unwanted horizontal overflow can be frustrating. One common cause is using 100vw for width, which doesn't consider the presence of scroll bars in certain operating systems. Another issue may arise when images don't have max-width set to 100%, causing overflow when their natural size exceeds the viewport. Using overflow-x: hidden on the body element is a quick fix, but it doesn't address the underlying cause. It's recommended to find the specific element responsible for the overflow and apply overflow-x accordingly. Transforms, such as rotations or translations, can also impact flow and potentially cause overflow.
In this episode we're overjoyed to overexplain why you may be having overflow in your page. somewhere over the rainbow, an overheating developer overcooked the inline sizes and ended up oversleeping for work the next day. Now let's overanalyze and overshare about CSS overflow.