Shniper
Shniper

Reputation: 854

SCSS nesting nth-of-type

Using SCSS and have a nested element which I am trying to nest an nth-of-type() rule into but it hasn't worked anyway I type it. I want every odd el_header element to be white text and every even one to be black.

.el {
  height: 500px;
  width: 500px;

  &_header {
    height: 100%;
    width: 10%;
    background: #555;
    display: inline-block;
    line-height: 500px;
    text-align: center;

    &nth-of-type(odd) {
      color: black;
    }
    &nth-of-type(even) {
      color: white;
    }

  }
}

DEMO

Upvotes: 1

Views: 8512

Answers (1)

herrh
herrh

Reputation: 1368

You just forgot the : after &.

Use

&:nth-of-type(odd){...}

&:nth-of-type(even){...}

and it will work. See updated fiddle

Upvotes: 9

Related Questions