一篇文章,主要聊到 Web 开发中处理元素堆叠导致 z-index 数字越卷越大,难以控制的话题,涉及到 层叠上下文 Stacking Contxts 的概念。
Understanding & Debugging Stacking Contexts (and the Z-Index) | Lullabot
觉得这句讲的挺好,在项目中处理层叠问题时,也需要以一个“相对”的思路去控制它,而非具体的数字:
The key to maintainable z-index values is understanding that z-index values can’t always be directly compared. They’re not an absolute measurement along an imaginary ruler extending out of the viewport; rather, they are a relative order between elements within the same stacking context.
另外文中还提到一个,辅助寻找 Stacking Contexts 的 DevTools 扩展插件。
https://github.com/andreadev-it/stacking-contexts-inspector