Reputation: 12729
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
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