user944513
user944513

Reputation: 12729

why background color not change on focus of div?

I have div in which I have input and button .I want to change the background-color of parent div when i focused to input div .but it is not working .Can we do this using css not javascript.

I tried like this

.a:focus{
  background-color:red;
  border:2px solid grey;
} 

But it not work why ?

I want when I focus to input field than parent div which have class "a" will become background-color:red and border become red

here is my code https://jsbin.com/kimejehane/1/edit?html,css,output

<div class="a">
    <div class="b">
      <input type="text">
      <button>aa</button>
    </div>
  </div>

Upvotes: 0

Views: 1373

Answers (1)

ImZedi
ImZedi

Reputation: 294

If you want to change background of parant div having class b, then try out this.

.b:focus-within {
  background-color:red;
  border:2px solid grey;
}

Upvotes: 3

Related Questions