Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which element is causing the horizontal scrollbar? Automated detection [closed]

Horizontal scrollbars on web sites and HTML apps are generally bad for usability and unwanted. It's reasonably common to find them cropping up unexpectedly and I'm in need of a way to quickly debug and remove them.

What is a quick and easy way to find offending HTML elements in your design?

Yes, you can go through your page deleting/hiding elements one by one until you find a suspect, but this is time consuming, especially if there are multiple offending elements. It would be great to click a shortcut or run a script and have all the suspected elements highlighted, outlined or printed to the console.

To clarify: the problem is not how to solve it, but how to detect it. I'd like a general solution which can work whenever this issue appears.

like image 360
webextensions.org Avatar asked Jan 03 '13 20:01

webextensions.org


People also ask

How do you know which element is causing horizontal scroll?

To find out which elements cause a horizontal scrollbar, you can use the devtools to delete elements one by one until the scrollbar disappears.

What cause horizontal scroll bar?

You horizontal scrollbar is caused because your site-section has a width of 100vw. The browser is fine with that but it also accounts for margin and padding (blue and red). This results in an overflow and thus the browser adds a horizontal scrollbar (along with a vertical one); The best way to fix this is to use calc.

What is causing horizontal overflow?

An overflow issue occurs when a horizontal scrollbar unintentionally appears on a web page, allowing the user to scroll horizontally. It can be caused by different factors. It could occur because of unexpectedly wide content or a fixed-width element that is wider than the viewport.

How do I fix the horizontal scrollbar in HTML?

To hide the horizontal scrollbar and prevent horizontal scrolling, use overflow-x: hidden: HTML.


1 Answers

In a narrower scope, you can use jQuery (to get the width) and node.scrollWidth to get nodes that have content that overflow their bounds.

http://jsfiddle.net/tomprogramming/v3Q6W/3/

like image 170
Thomas Jones Avatar answered Oct 12 '22 02:10

Thomas Jones