Skip to content

Instantly share code, notes, and snippets.

@ThatGuySam
Last active August 9, 2017 21:10
Show Gist options
  • Save ThatGuySam/9bcb1a8bb10ed8adbd7b7499a3da0a81 to your computer and use it in GitHub Desktop.
Save ThatGuySam/9bcb1a8bb10ed8adbd7b7499a3da0a81 to your computer and use it in GitHub Desktop.
Find those freaking overflowing html elements that add stupid horizontal space outside of your html document
// Determines if the passed element is overflowing its bounds,
// Will temporarily modify the "overflow" style to detect this
// if necessary.
var checkOverflow = function(el)
{
var curOverflow = el.style.overflow;
if ( !curOverflow || curOverflow === "visible" ){
el.style.overflow = "hidden";
}
var isOverflowing = el.clientWidth < el.scrollWidth;
el.style.overflow = curOverflow;
return isOverflowing;
}
// Test every element that exists
// and if it's overflowing log it
// and log it's width
window.whatsOverflowing = function(){
var elements = document.getElementsByTagName("*");
for (var i=0; i < elements.length; i++) {
var isOverflowing = checkOverflow(elements[i]);
if( isOverflowing ) {
console.log( elements[i] );
console.log( elements[i].clientWidth );
}
}
}
// window.whatsOverflowing();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment