khollenbeck
khollenbeck

Reputation: 16157

SASS how to grab a value from a variable or use a variable like a list?

Is it possible to grab a specific value from a variable? I have been trying to make my variable as a list, but I keep getting errors.

For starters I have an @include(); like so...

@include myMixin (2px 4px 13px 0px);

And then I have a mixin like this...

@mixin($myVar){

}

And from here I have the following variable.. $myVar: $myVar; like so...

@mixin($myVar){
  $myVar:$myVar;

 //when I do this I get an error in my sass watch
 @debug Second value is nth($myVar, 2);

 //This is how I want to use it...
 margin-right:nth($myVar, 2);
}

My Error:

Sass list index is 2 but list is only 1 item long for "nth:

SUMMARY:

This approach doesn't seem to be working so I am thinking maybe there is a different way to do this, I don't want to get into too much detail as there are a lot of other things going on. Basically my end goal is to have a variable equal a set of values and to be able to grab /use a specific values somehow. Any help is much appreciated.. Thanks in advance.

Upvotes: 1

Views: 684

Answers (1)

cimmanon
cimmanon

Reputation: 68339

You have the right idea:

@mixin myMixin($myVar){
    //when I do this I get an error in my sass watch
    @debug Second value is nth($myVar, 2);

    //This is how I want to use it...
    margin-right: nth($myVar, 2);
}
.test {
    @include myMixin(2px 4px 13px 0px);
}

DEBUG: Second value is 4px

.test {
  margin-right: 4px;
}

Is there something else here that you're not showing that is possibly messing this up?

Upvotes: 1

Related Questions