0
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.

4
  • I'd suggest taking a look at LESS/SASS Commented Mar 15, 2014 at 1:06
  • 2
    Do you want anything under div.a to be color: red? Commented Mar 15, 2014 at 1:06
  • @PhilippeSignoret No. Just defined elements. Commented Mar 15, 2014 at 1:11
  • Oh, then with regular ol' CSS I don't think it can get shorter. You could omit the 'div' in 'div.a' if it's OK for all class="a" elements to behave similarly. Commented Mar 15, 2014 at 1:13

3 Answers 3

3

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;
}
Sign up to request clarification or add additional context in comments.

1 Comment

This really seems like the way to go. I think it makes the html/css easier to follow.
1

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;
    }
}

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.