I want to use css to target every "info" class that has an "error" class two divs above. Is there a way to do this with css? For example, I want the "info" class to have a red border if the field-label above it has an "error" class.
Asked
Active
Viewed 53 times
0
-
Please include a [mcve] to your question. Adding only an image of code is not helpful [Read Why](https://meta.stackoverflow.com/a/285557) – blurfus May 14 '20 at 17:30
-
btw, in your image, `.info` is not inside `.error` - based on your example, you could try `.error + .input-field > .info` – blurfus May 14 '20 at 17:31
2 Answers
1
.error + .input-field .info {}
.error + .input-field
will select only .input-field
div that is immediately preceded by the .error
div. So the above code will select any element with .info
class, which is inside .input-field
div.
.error + .input-field > .info {}
The code above will select any .info
element which is direct children of .input-field
div.
.error + .input-field > .info:nth-child(1) {}
The code above will select first instance of .info
element which is direct children of .input-field
div.

Mishel Tanvir Habib
- 1,112
- 11
- 16