0

I have a case where I use a frontend framework to beauty my website. In this framework when an input is focused (I mean when someone clicked input), the class is toggled. Unfortunately by jQuery. And the whole problem is I don't want to use a jQuery.

Is there any way to toggle class in CSS only?

<input type="text" name="street">
<label class="active"></label>

Class 'active' should be toggled in label element when input was clicked. Thanks!

EDIT: that topic is from 2013' and dosn't satisfy me :( c

Temani Afif
  • 245,468
  • 26
  • 309
  • 415
tylkonachwile
  • 2,025
  • 4
  • 16
  • 28

1 Answers1

0

You can write CSS clases for both states in order to avoid messing with jQuery actions but still have the look & feel you expect.

Something like this can make the trick (CSS):

label.active, label.active:focus, label.active:focus-within, label:not(.active){
  //Your look and feel
}
leopinzon
  • 707
  • 6
  • 13