0

I would like to change the css of all labels for all inputs that are disabled. I currently use this in a global scss style sheet:

  ::ng-deep input:disabled+label {
    color: rgb(223, 107, 107) !important;
  }

<label for="someLabel">someLabel</label>
<input id="someLabel" disabled>

But the css is not applied to the label.

Stefan
  • 1,122
  • 3
  • 14
  • 38

2 Answers2

2

The + plus sign is used to select the elements that are placed immediately after the specified element. Therefore your CSS is looking for a label tag after a disabled input tag.

You can achieve more or less the same result like that:

input:disabled + label {
  color: rgb(223, 107, 107) !important;
}


.flex {
  display: flex;
  flex-direction: row-reverse;
  float: left;
}
<div class="flex">
  <input id="someLabel" disabled />
  <label for="someLabel">someLabel</label>
</div>
Tolga Yiğit
  • 402
  • 3
  • 11
2

You can use :has() selector to find previous selector like below:

label:has(+ input:disabled) {
   color: rgb(223, 107, 107);
}
Hardik Solanki
  • 3,153
  • 1
  • 17
  • 28