This content originally appeared on David Walsh Blog and was authored by David Walsh
Every once in a while you encounter a CSS annoyance that takes some cleverness to discover. One such case rears its ugly head in unwanted and unexpected scrollbars. When I see unwanted scrollbars, I usually open developer tools, click the element inspector, and hover around until I find the villainous HTML element. As a visual person, I find that process effective but not efficient. Recently I was made aware of a programmatic way to find the scoundrel element with JavaScript!
To find the element summoning demon scrollbars, you can use the following JavaScript:
document.querySelectorAll('*').forEach(el => { if (el.offsetWidth > document.documentElement.offsetWidth) { console.log('Found the worst element ever: ', el); } });
After the element has been logged to the console, you can pinpoint it and play with punishments in the element inspector as you see fit.
I’m always guilty of reverting to my old ways, i.e. visual inspection, but having a programmatic solution is so much faster and convenient!
The post Detect CSS Overflow Elements appeared first on David Walsh Blog.
This content originally appeared on David Walsh Blog and was authored by David Walsh
David Walsh | Sciencx (2021-04-08T10:59:14+00:00) Detect CSS Overflow Elements. Retrieved from https://www.scien.cx/2021/04/08/detect-css-overflow-elements/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.