Is it possible to reference a further parent than just the one above?

前端 未结 3 1349
梦如初夏
梦如初夏 2020-12-02 01:52

I have the following sample code:

.level1 {
   // css

  .level2 {
  // css

     . level3 {
     // css
     color: red;
  }
}

And then

3条回答
  •  再見小時候
    2020-12-02 01:59

    I wasn't planning on answering my own question, but it seems that I found out exactly what I was looking for only it has recently being added to sass and will be available on sass 3.4. I believe there's a prerelease to tried but I havent tried it yet.

    Basically what I was looking has been answered to me on github:

    https://github.com/sass/sass/issues/286#issuecomment-49112243

    So on 3.4 you can do:

    .level1 {
      .level2 {
        .level3 {
           @at-root #{selector-append(".blue", &)} {
            color: blue;
          }
          color: red;
        }
      }
    }
    

    which is exactly what I was looking for.

    There's a bunch of addition related to the parent selector (&), you can learn more from it at https://github.com/sass/sass/issues/1117

    Bear in mind though, that at the time of writing this answer, all of this is rather new.

    Also see: https://github.com/sass/sass/blob/master/doc-src/SASS_CHANGELOG.md And: http://www.phase2technology.com/blog/everything-you-need-to-know-about-sass-3-4/

提交回复
热议问题