1

input {
  background: transparent;
  position: relative;
}

label {
  color: black;
}

input:focus + label {
  color: red !important;
  border: 1px solid white;
}
<div class="input-box d-flex flex-column">
  <label for="name" class="py-2">Your Name</label>
  <input class="py-2 border-0 text-white" id="name" type="text" />
</div>

I want to change the label text color, when i focus in a input of a form.

Mr KnoX
  • 11
  • 3

1 Answers1

3

You can't select UP the DOM.

What you can use is :focus-within on the wrapping div and then select downwards to the label..

input {
  background: transparent;
}

label {
  color: black;
}

.input-box:focus-within label {
  color: red !important;
  border: 1px solid white;
}
<div class="input-box d-flex flex-column">
  <label for="name" class="py-2">Your Name</label>
  <input class="py-2 border-0 text-white" id="name" type="text" />
</div>
Paulie_D
  • 107,962
  • 13
  • 142
  • 161