How can I concatenate a Sass variable?
This is the the code in the scss file.
$url = 'siteurl.com'; #some-div{ background-image: url(+ $url +/images/img.jpg); }
I want the result in the CSS file to be:
#some-div{ background-image: url('siteurl.com/images/img.jpg'); }
I found this question, but it didn't worked for me: Trying to concatenate Sass variable and a string
The single Sass string operator is concatenation. Strings can be concatenated (linked together) using the + operator. If you mix quoted and unquoted strings when concatenating, the result will be whichever is on the left side of the operator.
Concatenation is the process of combining two or more strings to form a new string by subsequently appending the next string to the end of the previous strings. In Java, two strings can be concatenated by using the + or += operator, or through the concat() method, defined in the java. lang. String class.
Concatenating combines two or more SAS data sets, one after the other, into a single SAS data set. You concatenate data sets by using either the SET statement in a DATA step or the APPEND procedure.
Multiple issues here, the correct syntax is
$url: 'siteurl.com'; #some-div{ background-image: url($url + '/images/img.jpg'); }
:
and not =
+
symbol before $url
You can see the above code in action at SassMeister
Use this:
$domain: 'domain.com'; #some-div { background-image: url('#{$domain}/images/img.jpg'); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With