0

Why doesn't this work? Specifically, I'm trying to show some text in a div, if it contains a hidden form...

form.hidden {
  display: none;
}

div:has(form.hidden)::before {
  color: red;
  font-size: x-large;
  content: 'This DIV has a hidden FORM';
}
<div>
  <form class="hidden">
    form
  </form>
</div>
user4893295
  • 533
  • 6
  • 25

1 Answers1

3

:has() is an experimental feature, no browsers support it yet . Please see the browser compatibility chart: https://developer.mozilla.org/en-US/docs/Web/CSS/:has

The spec also indicates that it cannot be used in stylesheets:

The :has() pseudo-class takes a selector list as an argument. In the current specification :has is not marked as part of the live selector profile, which means it can not be used within stylesheets; only with functions like document.querySelector().

skyline3000
  • 7,639
  • 2
  • 24
  • 33