简体   繁体   中英

What does sharp (#) (e.g. #{$variable}) mean in SCSS?

I was checking out an article and came across something like the following:

$desktop-width: 1024px;

@mixin desktop {
  @media(min-width: #{$desktop-width}) {
    ...
  }
}

And was wondering why the use of sharp (#)? Can't you just do min-width: $desktop-width ?

Thank you in advance and will accept answer/up vote

#{}负责字符串插值,因此在上面的示例中不需要它,可以省略。

#{} 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 eg selector names in mixins. For example.

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

$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.

It, combined with {} indicates something that should be interpolated .

ie replaced with the value of a variable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM