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

Color contrast should ignore overlapping elements that have transparent background #3464

Open
straker opened this issue May 18, 2022 · 9 comments
Labels
color contrast Color contrast issues fix Bug fixes pr A pr has been created for the issue
Milestone

Comments

@straker
Copy link
Contributor

straker commented May 18, 2022

Take the following example:

<style>
.overlap {
  position: absolute;
  top: 0;
  left: 0;
  width: 100px;
  height: 100px;
}
</style>

<span>Hello World</span>
<div class="overlap"></div>

This causes an incomplete result for color contrast because the .overlap element is on top of the <span> element in the DOM stack. However since the .overlap element has a transparent background it should just be ignored.

This same problem happens with Material Button components due to the ripple effect element that overlaps the button text.

<button class="mdc-button mdc-button--raised">
  <span class="mdc-button__label">Button</span>
  <div class="mdc-button__ripple"></div>
</button>
@straker straker added fix Bug fixes color contrast Color contrast issues labels May 18, 2022
@straker straker added this to the Axe-core 4.5 milestone May 18, 2022
@straker
Copy link
Contributor Author

straker commented May 18, 2022

We should look into restricting exactly what is ignored, as images or iframes that overlap won't have a background color but will interfere with the element. So possible solution is to ignore the element if it meets all of the following conditions:

  • has a fully transparent background
  • has no text content
  • has a presentational or no role

@WilcoFiers
Copy link
Contributor

It also can't have CSS filters, thick border, pseudo elements, embedded graphical content like img, canvas, object. There are a ton of ways in which something that at first glance may seem like an empty div, for it to have an impact on content that's behind it.

I think that 9 out of 10 times when we see a transparent element on top of text content, it's there to have some kind of effect on things that are behind it. Why would people put completely empty divs on top of their content?

@WilcoFiers WilcoFiers modified the milestone: Axe-core 4.5 May 20, 2022
@straker
Copy link
Contributor Author

straker commented Jun 3, 2022

A good example of this is the home page of https://arstechnica.com/. They use empty anchor tags with aria-hidden=true and tabindex=-1 to cover the entire card for the article links which makes every single node in the card return as needs review (165 total color contrast needs review items).

We could scope the requirement to ignore the element based on:

  • does not have text content
  • does not have a background color (i.e. transparent)
  • does not have pseudo elements
  • does not have a border, outline, filter, etc.

@straker
Copy link
Contributor Author

straker commented Oct 3, 2022

Another place this happens on is Material Inputs https://material.angular.io/components/input/overview. The inputs each contain a span which in turn contains the label element for the input. The span overlaps the input, but the label does not. Since the span itself has no background and no direct text children, we should ignore it as well.

@padmavemulapati
Copy link

Validated with the latest develop branch code base, for the test script:

<style>
.overlap {
  position: absolute;
  top: 0;
  left: 0;
  width: 100px;
  height: 100px;
}
</style>

<span>Hello World</span>
<div class="overlap"></div>

This snippet is giving an incomplete result for color contrast because the .overlap element is on top of the <span> element in the DOM stack.

Image

and with the below test script:

<button class="mdc-button mdc-button--raised">
  <span class="mdc-button__label">Button</span>
  <div class="mdc-button__ripple"></div>
</button>

the ripple effect element that overlaps the button text, so it is passing

@CHE1RON
Copy link

CHE1RON commented Jan 27, 2023

I know this was closed some time ago, but is there any chance to revive #3583 in order to prevent incomplete tests? 😕

@WilcoFiers
Copy link
Contributor

This was closed by mistake. We're going to look at this again.

@WilcoFiers WilcoFiers reopened this Jul 12, 2023
@WilcoFiers WilcoFiers modified the milestones: Axe-core 4.5, Axe-core 4.9 Jul 12, 2023
@CHE1RON
Copy link

CHE1RON commented Jul 12, 2023

Thanks! 🙏

@semisse
Copy link

semisse commented Mar 7, 2024

please, fix this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
color contrast Color contrast issues fix Bug fixes pr A pr has been created for the issue
Projects
None yet
Development

No branches or pull requests

5 participants