Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does .# mean in SCSS?

Tags:

css

sass

I have an example code with .#

.#{$item} {
    background: $item;
  }

I can't find anything on google apart from another example

$fa-css-prefix: fa;
.#{$fa-css-prefix} { ... }

What does it mean?

like image 487
Tristan Warren Avatar asked Jun 13 '26 06:06

Tristan Warren


2 Answers

There are two parts in this expression, The . is the css class selector, #{} interpolation syntax it allows the using of the variables in selectors and property names

$name: foo;
$attr: border;
p.#{$name} {
  #{$attr}-color: blue;
}

the generated css:

p.foo {
  border-color: blue; }
like image 144
Kld Avatar answered Jun 14 '26 21:06

Kld


The . Is actually for a classname and not related to the #. #{$name} is to output a variable name in escaped format. I case the variable had characters such as dash sass won't treat it as a subtract.

Here's an example: Using SASS, How can I escape the slash character in a font declaration?

like image 29
jerrylow Avatar answered Jun 14 '26 21:06

jerrylow



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!