-1

From the image. How would you be able to apply a property to the label from the focus of the input?

I saw some examples but that only work if the label immediately after the input. Then it would be enough to use the + of the css .. but in this case it is one level outside the parent input.

this only works if the label is immediately after the input. It's not the case.

.container input:focus + label{
    font-size: 12px !important;
    margin-top: 0 !important;
}

enter image description here

Renato Souza de Oliveira
  • 4,236
  • 4
  • 20
  • 31

1 Answers1

2

You can use the :focus-within pseudo-class as well as the ~ selector.

div.input:focus-within ~ label {
  color: red;
}
<div class="input">
  <input type="text">
</div>
<label for="">label</label>
Simplicius
  • 2,009
  • 1
  • 5
  • 19