Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[css-stacking] named stacking contexts and containing blocks #9108

Open
mayank99 opened this issue Jul 24, 2023 · 0 comments
Open

[css-stacking] named stacking contexts and containing blocks #9108

mayank99 opened this issue Jul 24, 2023 · 0 comments
Labels
css-stacking-3 CSS Stacking Contexts Level 3

Comments

@mayank99
Copy link

mayank99 commented Jul 24, 2023

While thinking about #9107, i was wondering if it would be possible to do something like this:

.foo {
  stacking-context-name: foo;

  .bar {
    /*
     * this is only relative to other z-indices in the "foo" stacking context.
     * it "does not exist" as far as any other z-indices are concerned.
     */
    z-index-context: foo;
    z-index: -1;
  }
}

Containers can overlap, so if stacking contexts could also overlap, this could open up some cool possibilities. In the example above, a parent of .foo could create a stacking context that a child of .foo would be able to use.

Not sure if this would be achievable but it would certainly be useful.

Currently the next best option is to explicitly create a stacking context, but it's not airtight.

.foo {
  isolation: isolate; /* create stacking context */

  .bar {
    /*
     * this is relative to every z-index inside .foo :(
     * (until the next nested stacking context is found)
     */
    z-index:-1;
  }
}

The same idea could be applied to containing blocks.

.foo {
  containing-block-name: foo;
  position: relative;

  .bar {
    position: relative;
    transform: translateX(0); /* oops, created a containing block */

    .baz {
      /* still placed relative to "foo", not nearest CB :)  */
      position-containing-block: foo;
      position: fixed;
      inset-inline-end: 0;
    }
  }
}

But it looks like this might be possible to achieve using anchor positioning? Related issues:

@fantasai fantasai added css-position-3 Current Work css-stacking-3 CSS Stacking Contexts Level 3 and removed css-position-3 Current Work labels Jan 9, 2024
@fantasai fantasai changed the title named stacking contexts and containing blocks [css-stacking] named stacking contexts and containing blocks Jan 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
css-stacking-3 CSS Stacking Contexts Level 3
Projects
None yet
Development

No branches or pull requests

2 participants