Skip to content

Color-contrast incorrect stack due to flex children allowing z-index #3881

@straker

Description

@straker

Consider the following HTML:

Details
<style>
  #shadow {
    display: flex;
  }

  #backdrop {
    position: absolute;
    z-index: 1;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
  }
</style>

<div id="backdrop"></div>
<div id="shadow"></div>

<script>
  const root = shadow.attachShadow({ mode: 'open' })
  root.innerHTML = `
  <div>asf</div>
  <style>
  div {
    background: white;
    z-index: 1;
  }
  </style>`
</script>

The div child of the shadow root is allowed to have a z-index even though it is not using position. Turns out that flex items are allowed to use z-index and they are treated as though the element is positioned.

When we calculate the stacking order for elements, we need to take into account flex children and treat them as though they are positioned. An example of doing that can be found in the calculation for stacking context.

Metadata

Metadata

Assignees

Labels

fixBug fixesprA pr has been created for the issuerulesIssue or false result from an axe-core rulesupport

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions