in Education by
I'm trying to use string interpolation on my variable to reference another variable: // Set up variable and mixin $foo-baz: 20px; @mixin do-this($bar) { width: $foo-#{$bar}; } // Use mixin by passing 'baz' string as a param for use $foo-baz variable in the mixin @include do-this('baz'); But when I do this, I get the following error: Undefined variable: "$foo-". Does Sass support PHP-style variable variables? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
This is actually possible to do using SASS maps instead of variables. Here is a quick example: Referencing dynamically: $colors: ( blue: #007dc6, blue-hover: #3da1e0 ); @mixin colorSet($colorName) { color: map-get($colors, $colorName); &:hover { color: map-get($colors, #{$colorName}-hover); } } a { @include colorSet(blue); } Outputs as: a { color:#007dc6 } a:hover { color:#3da1e0 } Creating dynamically: @function addColorSet($colorName, $colorValue, $colorHoverValue: null) { $colorHoverValue: if($colorHoverValue == null, darken( $colorValue, 10% ), $colorHoverValue); $colors: map-merge($colors, ( $colorName: $colorValue, #{$colorName}-hover: $colorHoverValue )); @return $colors; } @each $color in blue, red { @if not map-has-key($colors, $color) { $colors: addColorSet($color, $color); } a { &.#{$color} { @include colorSet($color); } } } Outputs as: a.blue { color: #007dc6; } a.blue:hover { color: #3da1e0; } a.red { color: red; } a.red:hover { color: #cc0000; }

Related questions

0 votes
    What is the meaning of _ after for in this code? if tbh.bag: n = 0 for _ in tbh.bag.atom_set(): n += 1 Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    Coming from a C# background the naming convention for variables and method names are usually either Camel Case or ... for Python? Select the correct answer from above options...
asked Jan 27, 2022 in Education by JackTerrance
0 votes
    Here is the code class method { int counter = 0; public static void main(String[] args) { System.out. ... variables of the class? Select the correct answer from above options...
asked Jan 21, 2022 in Education by JackTerrance
0 votes
    In my angular project, I have some css variables defined in top level styles.scss file like this. I ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    Variables that gets created dynamically when a function (such as malloc()) is called is created in the form of ... Security questions and answers pdf, mcq on Cyber Security pdf,...
asked Nov 4, 2021 in Education by JackTerrance
0 votes
    To add, delete objects in a report, applying conditional formatting, applying formulas in report, creating variables, you should open Webi document in which of the following mode?...
asked Mar 13, 2021 in Technology by JackTerrance
0 votes
    After installing the F# September CTP (1.9.6.2), Visual Studio 2008 frequently gives an error "Microsoft ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 10, 2022 in Education by JackTerrance
0 votes
    I need to remove a highly referenced table in a SQL Server database. How can I get a list of all the ... of the management studio.) Select the correct answer from above options...
asked Jan 28, 2022 in Education by JackTerrance
0 votes
    = A 1 * B14 is an example of which type of referencing? a. Relative b. Absolute c. Mixed d. None of these Select the correct answer from above options...
asked Dec 26, 2021 in Education by JackTerrance
0 votes
    Can we deploy Azure Functions referencing a zip file with relative path?...
asked Mar 10, 2021 in Technology by JackTerrance
0 votes
    How can I apply my div position x value to a variable? And how to iterate it in a for loop? ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    I have been developing a webpage which uses n number of dropdownlists which are binding dynamically inside a ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 18, 2022 in Education by JackTerrance
0 votes
    I've noticed that the chart object has a fontSize property, but just changing it does nothing, even with ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 2, 2022 in Education by JackTerrance
0 votes
    I would like to dynamically assign a class to a specific cell in a table. An object in "cols" ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 21, 2022 in Education by JackTerrance
0 votes
    I would like to dynamically assign a class to a specific cell in a table. An object in "cols" ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 15, 2022 in Education by JackTerrance
...