It’s always the stacking context.

In “What the heck, z-index??,” Josh Comeau makes the analogy of layer groups in design software like Photoshop or Figma to stacking contexts in CSS. If you’ve got an element in a layer group A in Photoshop that …


The post It’s always the stacking context. appeared first on CSS-Tricks.

You can support CSS-Tricks by being an MVP Supporter.


This content originally appeared on CSS-Tricks and was authored by Chris Coyier

In “What the heck, z-index??,” Josh Comeau makes the analogy of layer groups in design software like Photoshop or Figma to stacking contexts in CSS. If you’ve got an element in a layer group A in Photoshop that is below layer group B, there is nothing you can do to push a child of A on top of anything in B, aside from moving the whole layer group A above B, or getting rid of the groupings.

Nothing is going to put that moustache on top of the dog unless you get it out of that stacking context or move the whole stacking context.

Here’s a reduced case:

There is no z-index value that is going to get “Big Thing” on top of the tan <main> element there. But as Josh notes in the article, there are a variety of solutions, such as preventing a stacking context from triggering unnecessarily, or doing a little DOM shuffling to make things work. Like in the example above, “Big Thing” doesn’t need to be a child of the header — and if it wasn’t, the stacking context wouldn’t be as relevant.

If you’re a fan of your tools helping you diagnose this kind of thing, read to the bottom of Josh’s article for a few interesting ones.

Direct Link to ArticlePermalink


The post It’s always the stacking context. appeared first on CSS-Tricks.

You can support CSS-Tricks by being an MVP Supporter.


This content originally appeared on CSS-Tricks and was authored by Chris Coyier


Print Share Comment Cite Upload Translate Updates
APA

Chris Coyier | Sciencx (2021-03-22T19:27:56+00:00) It’s always the stacking context.. Retrieved from https://www.scien.cx/2021/03/22/its-always-the-stacking-context/

MLA
" » It’s always the stacking context.." Chris Coyier | Sciencx - Monday March 22, 2021, https://www.scien.cx/2021/03/22/its-always-the-stacking-context/
HARVARD
Chris Coyier | Sciencx Monday March 22, 2021 » It’s always the stacking context.., viewed ,<https://www.scien.cx/2021/03/22/its-always-the-stacking-context/>
VANCOUVER
Chris Coyier | Sciencx - » It’s always the stacking context.. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/03/22/its-always-the-stacking-context/
CHICAGO
" » It’s always the stacking context.." Chris Coyier | Sciencx - Accessed . https://www.scien.cx/2021/03/22/its-always-the-stacking-context/
IEEE
" » It’s always the stacking context.." Chris Coyier | Sciencx [Online]. Available: https://www.scien.cx/2021/03/22/its-always-the-stacking-context/. [Accessed: ]
rf:citation
» It’s always the stacking context. | Chris Coyier | Sciencx | https://www.scien.cx/2021/03/22/its-always-the-stacking-context/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.