blueFast
blueFast

Reputation: 44491

Apply style to more than one element

This is an easy one, but i can no find the right way to do this. I have the following style definition:

.main_section nav a {
    color:#999;
    ...
}

So this style applies to the a in the nav in the .main_section. Now I want to extend this so that also li elements are affected. What I would do is to duplicate the code, like:

.main_section nav li {
    color:#999;
    ...
}

But this just feels wrong. I want to unify both style specs into one. How can I do that?

Upvotes: 0

Views: 1288

Answers (3)

Arun Bertil
Arun Bertil

Reputation: 4648

Try

.main_section nav a, .main_section nav li 
{
   color:#999;
    ...

}

Upvotes: 1

Martin
Martin

Reputation: 176

Have you tried using a CSS preprocessor such as LESS or SASS.

Using one of these you would be able to write your code like the following:

.main_section {
    nav {
        a,
        li {
            color: #999;
        }
    }
}

Upvotes: 1

Sachin
Sachin

Reputation: 40990

use comma (,) to define same style on multiple elements

.main_section nav a,.main_section nav li {
    color:#999;
    ...
}

Upvotes: 4

Related Questions