0

I'm curious as to if there's a way to do something like this:

#sidemenu {
  .unlocked {
    color: blue;
  }

  .locked {
    color: red;
  }
}

instead of having to write it out like:

#sidemenu .unlocked {
    color: blue;
}

#sidemenu .locked {
    color: red;
}
2
  • 2
    research about SASS SCSS Commented Apr 9, 2016 at 20:25
  • You're in for a magical discovery. Commented Apr 9, 2016 at 23:54

2 Answers 2

4

You can't have CSS like this natively, but you can write it initially using CSS pre-processors such as LESS and SASS. The code is then compiled down to normal CSS.

Sign up to request clarification or add additional context in comments.

Comments

2

Switch from vanilla css to SASS/SCSS or LESS.

Here's a small example between vanilla CSS and SCSS:

Vanilla CSS:

#sidemenu .unlocked {
    color: blue;
}

#sidemenu .locked {
    color:red;
}

SCSS:

#sidemenu
    .unlocked {
        color: blue;
    }

    .locked {
        color:red;
    }
}

As Scott mentioned above, the SASS/SCSS/LESS will be recompiled to Vanilla CSS once it's rendered though.

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.