Ben Nadel demonstrates how to apply consistent padding and element widths inside an overflow container in CSS when the overflow contents force horizontal scrolling to take place.
This is primarily a note to self; and, is something that has been covered several times on StackOverflow; but, I can never seem to remember the answer and end-up re-learning it each time. As such, I wanted to write it down! This post looks at how to get CSS padding and widths to work consistently inside an overflow: auto
(or [overflow: scroll](https://www.bennadel.com/blog/3642-use-css-overflow-auto-not-overflow-scroll-when-clipping-most-fixed-size-containers.htm)
if you feel that's necessary) container by using an inner-wrapper with display: inline-block
.
Run this demo in my JavaScript Demos project on GitHub.
View this code in my JavaScript Demos project on GitHub.
Most of the time, when we create an overflow container, we want to include some sort of inner-padding on that container such that the overflow contents don't butt-up against the scrollbars or the viewport border. To accomplish this, I usually just put in a "wrapper" div with a padding. And, as long as there is no horizontal scrolling, this works perfectly well.
However, the moment there is horizontal scrolling inside the overflow container, we see two unpleasant effects:
Some of the direct descendants of the "wrapper" element are "stuck" at 100% of the overflow container width and do not extend to match the width of the elements that are causing the horizontal scrolling.
The right padding of the "wrapper" element does not seem to get applied, allowing the overflow content to butt-up against the right-border of the overflow container.
HTML and CSS Tutorial for Beginners will provide you with a detailed and comprehensive knowledge about HTML. In this HTML Tutorial for Beginners you will learn HTML concepts from scratch and also how to create your first web page using HTML Tags.
HTML and CSS Tutorial for Beginners will provide you with a detailed and comprehensive knowledge about HTML. In this HTML Tutorial for Beginners you will learn HTML concepts from scratch and also how to create your first web page using HTML Tags.
The other day one of our students asked about possibility of having a CSS cheatsheet to help to decide on the best suited approach when doing this or that layout.
HTML Assignment Help Australia @30% OFF from Sample Assignment, with Our Best HTML assignment help experts. Get HTML homework help online at affordable price. 100% Plag free assignment solution.
Responsive Personal Portfolio Website using HTML CSS & JavaScriptImages: https://bit.ly/353QF2ZDemo: https://edem-portfolio.netlify.app/Source Code: https://...