spike
spike

Reputation: 10004

Apply style to multiple html elements of the same class with css or sass

I want to apply a style to all <p> and <input> elements of the numeric class using css.

Is it possible to consolidate this so that I only write "numeric" once?

p.numeric,input.numeric {
    float: right;
}

I'm also using sass, so if it's not possible in CSS is it possible with the sass additions?

Upvotes: 9

Views: 20699

Answers (2)

Rito
Rito

Reputation: 5203

yes it is possible:

p, input {
    &.numeric {
        float: right;
    }
}

The '&' is necceassry to connect with p/input. Without the result will be p .numeric {...}

Upvotes: 25

GordonM
GordonM

Reputation: 31730

You could simply do .numeric, but then it would apply to everything with a class of numeric. If you only want it to apply to paragraphs and inputs then what you're doing is the correct approach.

Upvotes: 1

Related Questions