How To Debug The Stack Of Elements via Edge Dev Tools
This JS code helps you to get an overview over the stack your HTML element is inside.
Flo
Steps to take
- Open the website you want to debug in edge
- Open the browser dev tools (Ctrl + Shift + I)
- Click Ctrl + Shift + C and select a HTML element
- Copy the following code in the browser console and click enter
- Now a table including your stack hierarchy is shown
function createsStackingContext(el) { const cs = getComputedStyle(el); const pos = cs.position; const z = cs.zIndex; const will = (cs.willChange || '').split(',').map(s => s.trim()); return ( (['relative','absolute','sticky','fixed'].includes(pos) && z !== 'auto') || pos === 'fixed' || parseFloat(cs.opacity) < 1 || cs.transform !== 'none' || cs.filter !== 'none' || cs.perspective !== 'none' || cs.mixBlendMode !== 'normal' || cs.isolation === 'isolate' || cs.clipPath !== 'none' || cs.backdropFilter !== 'none' || (cs.contain && cs.contain.includes('paint')) || will.some(p => ['transform','opacity','filter','perspective','clip-path','backdrop-filter'].includes(p)) ); }
function stackingChain(el) { const chain = []; let node = el; while (node && node.nodeType === 1) { const cs = getComputedStyle(node); chain.push({ el: node, tag: node.tagName.toLowerCase() + (node.id ? '#' + node.id : ''), classes: node.className || '', zIndex: cs.zIndex, position: cs.position, opacity: cs.opacity, transform: cs.transform, filter: cs.filter, perspective: cs.perspective, mixBlendMode: cs.mixBlendMode, isolation: cs.isolation, clipPath: cs.clipPath, contain: cs.contain, createsSC: createsStackingContext(node) }); node = node.parentElement; } return chain; }
// Usage: select an element in Elements panel, then run: const $1chain = stackingChain($0); // $0 is the currently selected element console.table($1chain, ['tag','classes','position','zIndex','opacity','transform','filter','contain','createsSC']);
You Might Also Like
SWS Snippet #0038: Christmas Tree with HTML and CSS
#html
How To Create A Logo With HTML And TailwindCSS
This post shows the process on how to create a blog logo with HTML and CSS.
#html
Create PNG file from <div>
This post explains how to add a button to a Astro page which downloads a certain <div> element in PNG format.
#html