Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
676 views
in Technique[技术] by (71.8m points)

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

I have the following sample code:

.level1 {
   // css

  .level2 {
  // css

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

And then

.level1.blue .level .level3 {
  color: blue
}

I would like to put the second rule somehow on the first bit of code, so that I don't repeat the structure again and I have both color possibilities above, is this possible in anyway?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...