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
501 views
in Technique[技术] by (71.8m points)

css - What does hash (#) sign do outside loops in SASS?

I've just come across the use of the hash sign outside of a loop in sass and I'm not sure what it's used for or what the reason for it is.

What's the difference between these two examples please? They both output the same css but the first doesn't allow classes only elements. Why is the first example in use in some places?

#{h1, h2, h3, h4, h5}
{
  color: #000;
}

h1, h2, h3, h4, h5
{
  color: #000;
}
See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

#{} is used for string interpolation: http://sass-lang.com/documentation/file.SASS_REFERENCE.html#interpolation_

There is one exception to this, though: when using #{} interpolation, quoted strings are unquoted. This makes it easier to use e.g. selector names in mixins. For example.

So this technique is used sometimes to allow using sass values in selectors. E.g.:

$gutter: 10;

.grid#{$gutter} {
    background: red;
}

Now to your question. I really don't see any reason why would anybody use string interpolation in this selector:

#{h1, h2, h3, h4, h5}
{
    color: #000;
}

My best guess is that sass variable will be added later to that selector, or the selector will be completely replaced with a variable.


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

...