kralco626 kralco626 - 1 year ago 104
CSS Question

Nesting CSS classes

Can I do something like the following?

.class1{some stuff}

.class2{class1;some more stuff}

Answer Source

Not possible with vanilla CSS. However you can use something like:

Sass makes CSS fun again. Sass is an extension of CSS3, adding nested rules, variables, mixins, selector inheritance, and more. It’s translated to well-formatted, standard CSS using the command line tool or a web-framework plugin.


Rather than constructing long selector names to specify inheritance, in Less you can simply nest selectors inside other selectors. This makes inheritance clear and style sheets shorter.


#header {
  color: red;
  a {
    font-weight: bold;
    text-decoration: none;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download