Recent chats
ASKGEEZ Q&A GUIDETechnology & devices

Why does a transform or opacity declaration create a new stacking context?

Quick answer

A transform or opacity below 1 can create a stacking context: a self-contained group whose descendants are stacked internally, while the group is handled as one unit by its parent context. So a child’s large z-index cannot independently jump above an outside element that stacks above the child’s parent context. Compare the parent contexts first; changing the child’s z-index alone may not help. [S1]

LET’S WORK THROUGH IT

The question, the details, the next step.

Question

I gave a dropdown a huge z-index, but it still appears behind a nearby panel. Why can that happen?

Geez

The child may be competing inside a stacking context that is itself behind the panel. A transform can create a stacking context, as can opacity below 1. A stacking context is self-contained: its descendants are ordered within it, and the context as a whole is treated as one unit in its parent. That means the dropdown’s z-index does not let it independently outrank an outside element that stacks above its parent context. [S1]

Think in terms of two comparisons: first, where the dropdown sits within its own context; second, where that entire context sits against the panel. If the parent context is behind the panel, raising the dropdown alone may change only the first comparison.

Follow-up question

Can you show the relationship with a small nested example?

Geez

Assume this markup is nested as shown, and assume the .card transform is present in the page’s CSS:

Page stacking context
├── .card (transform creates a stacking context)
│   └── .dropdown (z-index: 9999)
└── .panel (stacks above .card)

The key detail is that .dropdown belongs to .card’s context. Even with a very large z-index, it cannot independently rise above .panel if .card’s context is below .panel in the parent context. A transform creates a stacking context; the source also identifies opacity below 1 as one. [S1]

This diagram describes the assumed stacking relationship, not a promise that those selectors or values alone produce a particular result in every page. Check the actual element nesting and which contexts are being compared.

Follow-up question

What should I inspect before changing the z-index values?

Geez

Work from the outside inward:

  1. Identify the element that is visibly behind and the element that should appear above it.
  2. Trace each element upward through its ancestors to find the contexts containing them.
  3. Look for a transform or an opacity value below 1 on the relevant ancestors; either can create a context. [S1]
  4. Compare the two parent contexts in their shared parent context. If one is behind, adjusting only its child’s z-index will not let that child escape the context boundary. [S1]
  5. Decide whether to adjust the relationship between the parent contexts or change the structure so the elements participate in the intended context. Then retest the actual overlap.

Keep a short note of what you changed and which two elements you compared. That makes it easier to tell whether you fixed the parent-level ordering or merely altered the child’s internal order.

Follow-up question

How can I make that diagnosis clear to a teammate without claiming more than I know?

Geez

Share the nesting, the suspected context-creating declaration, and the comparison you want reviewed. For example:

Observed: [dropdown] appears behind [panel].
Nesting: [dropdown] is inside [parent]; [panel] is outside it.
Declaration to inspect: [transform or opacity below 1, if present].
Current hypothesis: [parent context] may stack below [panel].
Check requested: compare the two parent contexts before changing the child z-index.

Call it a hypothesis until you have checked the page’s actual declarations and stacking relationships. The cited reference establishes that transform and opacity below 1 create contexts and that descendants cannot independently outrank an element above their parent context. It does not establish which elements or values your particular page uses; inspect those directly. [S1]

A practical checklist

  • Name the two elements whose visible order is wrong.

  • Trace each element to the context that contains it.

  • Check relevant ancestors for transform or opacity below 1. [S1]

  • Compare the parent contexts before raising a child’s z-index. [S1]

  • Record the intended order and retest after any change.

A few more useful answers

Does a very large z-index always put an element on top?

No. A child is stacked within its context; it cannot independently outrank an outside element that stacks above its parent context. [S1]

Which two declarations are relevant to this problem?

The cited reference lists transform and opacity below 1 as stacking-context creators. [S1] This guide does not list every possible stacking-context trigger.

Should I remove the transform or opacity declaration?

Not automatically. First confirm which ancestor creates the context and whether changing the relationship between parent contexts or the element structure better fits the intended layout.

Sources

References used for this guide.

  1. [S1] Stacking context — CSS | MDN
    developer.mozilla.org · Checked

YOUR QUESTION. YOUR DETAILS.

Let’s work through your situation.

Get a tailored answer or help with your next task. Starts at $1, with a quote before you pay.

Ask your own question
← Back to Geez at Work