-3

Is there a way to apply a CSS selector such as focus to an element with two classes?

For example:

Given the following two classes in my CSS file:

.form__input:focus {
    border-color: blue;
    background: #ffffff;
}

.form__input-error {
    color: red;
    border-color: red;
}

is it possible to add the next:

.form__input .form__input-error:focus {
    color: red;
    border-color: red;
    background: #ffffff
}

I am asking, because in my specific case this is not working. I am not sure though whether this is due to the CSS or due to some javascript that I am performing.

Luk
  • 1,009
  • 2
  • 15
  • 33

1 Answers1

0

If you want to select an element with 2 classes, for instance, using your example...

.form__input:focus {
    border-color: blue;
    background: #ffffff;
}

.form__input-error {
    color: red;
    border-color: red;
}

/* 
    Note the lack of space between the classes.
    You can chain as many classes as you like.
*/
.form__input.form__input-error:focus {
    color: red;
    border-color: red;
    background: #ffffff
}