Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6173499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:35:13+00:00 2026-05-23T23:35:13+00:00

I have a problem with using variable defaults in Sass across scopes. My test

  • 0

I have a problem with using variable defaults in Sass across scopes. My test example is:

@mixin foo { 
        $val: 'red' !default; 
        .bar { 
                color: $val; 
        } 

} 

@include foo; 
.class1 { 
        $val: 'green'; 
        @include foo; 
        .class11 { 
                @include foo; 
        } 
} 

$val: 'black'; 
.class2 { 
        @include foo; 
} 

.class3 { 
        $val: 'blue'; 
        @include foo; 
} 

.class4 { 
        @include foo; 

}

It is compiles to:

.bar { 
  color: "red"; 

} 

.class1 .bar { 
  color: "red"; 
} 

.class1 .class11 .bar { 
  color: "red"; 
} 

.class2 .bar { 
  color: "black"; 
} 

.class3 .bar { 
  color: "blue"; 
} 

.class4 .bar { 
  color: "blue"; 

}

As you can see, variable $val is defined as ‘red’ !default in the mixin foo. I expect that importing the mixin would set $val to ‘red’ unless it is already defined. However, in class1, where $val is locally defined as ‘green’, importing the mixin foo overwrites it with ‘red’. In other classes, after the global definition of $val as ‘black’, importing the mixin works as expected and $val retains its already defined value.

What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T23:35:14+00:00Added an answer on May 23, 2026 at 11:35 pm

    Defining $val: 'green' locally in class1 does not alter $val: 'red' !default in mixin, because it look for global $val. At this point, no global $val has been defined.

    Then global $val is defined as ‘black’. After this $val in mixin look for global $val. At this point, global $val has been defined as ‘black’.

    Defining $val again locally will alter global $val that has been defined.

    @mixin foo 
      $val: 'red' !default // defined locally
      .bar
        color: $val
    
    @include foo // $val in mixin foo look for global $val. no global $val found, then 'red'
    
    .class1
      $val: 'green'
      @include foo // $val in mixin foo look for global $val. no global $val found, then 'red'
      color: $val // local $val 'green'
      .class11 
        @include foo // $val in mixin foo look for global $val. no global $val found, then 'red'
    
    $val: 'black' // defined globally at the first time
    
    .class2 
      @include foo // $val in mixin foo look for global $val. $val found, 'black'
    
    .class3
      $val: 'blue' // change the gobal $val
      @include foo // $val in mixin foo look for global $val. $val found, 'blue'
    
    .class4
      @include foo // $val in mixin foo look for global $val. $val found, 'blue'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following problem using template instantiation [*]. file foo.h class Foo {
I have a problem using the Java search function in Eclipse on a particular
I have the following problem using subversion: I'm currently working on the trunk of
I have the following problem in my Data Structures and Problem Solving using Java
I am having a problem using the Unity Application Block, I have created a
I have an odd problem...I'm using a documentation generator which generates a lot of
I have a problem with the following Linq query using Entity Framework: from o
I have a problem with binding data using BindingSource, typed dataset and DataGridView. My
I have a problem. I am coding using VS2008. I am calling webservices from
I have a problem with a memory leak in a .NET CF application. Using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.