qw3n qw3n - 4 months ago 27
Sass (Sass) Question

How do set a SCSS variable to an empty string?

I saw an interesting technique where you could use

&
to add a prefix to styles. So the problem I'm running into is making it an option not to set the prefix. No matter what I try I get
Error: Base-level rules cannot contain the parent-selector-referencing character '&'
from the sass compiler. So is there any way to add prefixing option but not make it required?

$prefix:"";
.#{$prefix}{
&color{
color:red;
}
}

Answer

Try to use inline condition for & sign. Like this:

$n: if($prefix != '', '&', '');

#{$n}color {
  color: red;
}
#{$n}left {
  float: left;
}