Nesting CSS classes

Update 1: There is a CSS3 spec for CSS level 3 nesting. It’s currently a draft.
https://tabatkins.github.io/specs/css-nesting/

Update 2 (2019): We now have a CSSWG editors draft
https://drafts.csswg.org/css-nesting-1/

Update 3 (2022): We now have a W3C First Public Working Draft https://www.w3.org/TR/css-nesting-1/

If approved, the syntax would look like this:

table.colortable {
  & td {
    text-align:center;
    &.c { text-transform:uppercase }
    &:first-child, &:first-child + td { border:1px solid black }
  }
  & th {
    text-align:center;
    background:black;
    color:white;
  }
}

.foo {
  color: red;
  @nest & > .bar {
    color: blue;
  }
}

.foo {
  color: red;
  @nest .parent & {
    color: blue;
  }
}

Leave a Comment