Skip to content

Instantly share code, notes, and snippets.

@dragontheory
Last active January 19, 2026 14:35
Show Gist options
  • Select an option

  • Save dragontheory/cb253a8b7e6148d138996333de923def to your computer and use it in GitHub Desktop.

Select an option

Save dragontheory/cb253a8b7e6148d138996333de923def to your computer and use it in GitHub Desktop.
Short, minimal, drop‑in CSS snippets for diagnosing common layout, spacing, overflow, stacking, focus/keyboard, contrast, and responsive issues.

Image

Here are short, drop‑in CSS snippets for diagnosing common layout, spacing, overflow, stacking, focus/keyboard, contrast, and responsive issues. These are minimal and meant to be temporarily added in DevTools or your CSS while debugging:


🧱 Layout & Spacing

Outline all elements (visualize boundaries to spot spacing/layout misalignments):

* {
  outline: 1px solid rgba(255, 0, 0, 0.3);
}

→ helps see box boundaries and unexpected margins/padding. (whitep4nth3r.com)

Force box-sizing: border-box globally (consistent sizing across elements):

*,
*::before,
*::after {
  box-sizing: border-box;
}

→ simplifies layout calculations and often fixes overflow/spacing weirdness. (Hoverify)


📏 Overflow Issues

Highlight overflowing elements (when horizontal scroll appears):

html, body {
  border: 5px dashed orange;
  overflow-x: hidden;
}

Temporary overflow debug: add red for overflowed content:

* {
  overflow: visible !important;
}

→ Useful to identify sources of unintended scrolling. (Smashing Magazine)


🧠 Stacking Contexts & Z‑Index

Add temporary high z‑index to root elements (brings all content to front):

body * {
  z-index: 9999 !important;
  position: relative !important;
}

Stacking context helper (outline and label):

[data-debug-stack] {
  outline: 2px solid magenta !important;
}

→ Stacking contexts are created by transforms, opacity, positioning, etc.; knowing what creates them is key to debugging. (MDN Web Docs)


⌨️ Focus & Keyboard

Focus rings on all focusable elements (improves keyboard debugging):

:focus {
  outline: 3px dashed #00f !important;
}

All interactive items visible on tab:

a, button, input, textarea, select {
  outline: 2px solid cyan !important;
}

🔆 Contrast

Temporary high‑contrast mode

html {
  filter: contrast(200%) saturate(150%);
}

Text vs. background overlay (detect low contrast):

* {
  background-color: rgba(255, 255, 0, 0.2) !important;
  color: #000 !important;
}

(Only for diagnostic use; validate with dedicated contrast tools)


📱 Responsive Debugging

Show active media query breakpoints:

body::before {
  content: "Viewport: " attr(data-width);
  position: fixed;
  top: 0;
  left: 0;
  background: black;
  color: white;
  padding: 2px 6px;
  font-size: 12px;
  z-index: 9999;
}

👉 To make this work dynamically, add in DevTools or injected script:

document.body.setAttribute('data-width', innerWidth + 'px');

Example responsive grid outline:

@media (max-width: 768px) {
  * {
    outline: 1px dashed green;
  }
}

🛠 Quick Utility Snippets

Center any element for alignment testing:

[data-debug-center] {
  position: fixed !important;
  top: 50% !important;
  left: 50% !important;
  transform: translate(-50%, -50%) !important;
  outline: 3px dashed magenta !important;
}

Disable transitions/animations during debug:

* {
  transition: none !important;
  animation: none !important;
}

🧠 Notes & Resources

  • Browser DevTools Layout/Box Model inspectors are indispensable for seeing computed margins, padding, and box sizes. (MDN Web Docs)
  • Stacking contexts are hierarchical and can be unintuitive; use dedicated stack inspectors in DevTools or tools like Polypane to visualize them. (Polypane)
  • Temporary outlines (using outline not border) don’t affect layout and make debugging easier. (whitep4nth3r.com)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment