Created
October 9, 2025 16:07
-
-
Save jimmynotjim/de9210663c18fed506147f545eaa5ad9 to your computer and use it in GitHub Desktop.
Highlight z-index to find layering bugs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Drop this in the console and highlight all the elements with a defined z-index. | |
// Helpful for debugging z-index issues. | |
function highlightElementsWithZIndex() { | |
const allElements = document.querySelectorAll('*'); | |
allElements.forEach(element => { | |
const zIndex = window.getComputedStyle(element).zIndex; | |
// Check if z-index is explicitly set and is a valid number (not "auto") | |
if (zIndex !== 'auto' && !isNaN(parseInt(zIndex))) { | |
element.style.border = '2px solid red'; | |
element.style.boxShadow = '0 0 5px rgba(255, 0, 0, 0.5)'; | |
console.log(`Element:`, element, `Z-index:`, zIndex); | |
} | |
}); | |
} | |
highlightElementsWithZIndex(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment