focus-within on a div or some other element with css only

Viewed 23

Hi,

I need an element to change when any of its child elements are focused so I tried focus-within. However, this doesnt seem to work for elements other than text inputs. Is there any alternative out there with CSS only?

Thank you.

form{ border:1px solid black;}
form:focus-within {
  background-color:red;
  
}
div {background-color:yellow;}
<form>
 <input type="text">
 <div>
  click here
 </div>
</form> 

0 Answers
Related