good_evening
good_evening

Reputation: 21759

How to simplify this css code?

div.a b, div.a strong, div.a i, div.a form, div.a span  {
  color: red
}

How to simplify this? To use div.a just once if possible, that would be perfection.

Upvotes: 0

Views: 63

Answers (3)

Anonymous
Anonymous

Reputation: 12027

There are a few options:

If you are targeting all child elements of div.a:

div.a *  {
    color: red
}

If you would like to not include a certain one, you could just use :not() of course.

Also, you could use less, which allows you to use:

div.a  {
    b, strong, i, form, span {
        color: red;
    }
}

Upvotes: 1

Philippe Signoret
Philippe Signoret

Reputation: 14376

How about the following?

div.a * { color: red; }

Every element under the <div class="a"> would have red text color, unless otherwise overridden.

If you only need b, form, strong, span, i to be red, then you probably have the shortest it can get without adding a class, such as what is proposed in the other answer.

Upvotes: 0

thesublimeobject
thesublimeobject

Reputation: 1403

If you really want to simplify it, you would put a common class on all of the elements, such that you have:

.red {
  color: red;
}

Upvotes: 3

Related Questions