-1

Given this code below, how can I add a border color in the input element if the parent has a sibling with this ID "message"?

<div>
  <input class="red"/>
</div>
<div id="message">
  Error message
</div>

I can't use JS in this case, only CSS. Thank you.

Johannes
  • 64,305
  • 18
  • 73
  • 130
Gustavo Rey
  • 115
  • 9

1 Answers1

2

You could use :has with the selector div:has( + div#message) > input:

div:has( + div#message) > input {
  border: solid 2px red;
}
<div>
  <input class="red" />
</div>
<div id="message">
  Error message
</div>
j08691
  • 204,283
  • 31
  • 260
  • 272