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

  • Home
  • SEARCH
  • 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 8609197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:49:22+00:00 2026-06-12T03:49:22+00:00

In my CSS I have to create classes that make reference to a ‘hair

  • 0

In my CSS I have to create classes that make reference to a ‘hair colour’ and ‘hairstyle’

I have written a mixin to help make my CSS writing more efficient:

@mixin hair($hair, $colour) {
    .hair-#{$colour} .#{$hair}  { 
background:image-url("xsppsfhair#{$hair}#{$colour}.svg") center top no-repeat, 
image-url("xsppsheadgrey.svg") center top no-repeat, 
image-url("xsppsbhair#{$hair}#{$colour}.svg") center top no-repeat;
}


}

@include hair(spikyboy, blonde);    
@include hair(curlyafroboy, blonde);    

This produces the following CSS

.hair-blonde .spikyboy {
  background: url('../images/xsppsfhairspikyboyblonde.svg?1348681869') center top no-repeat, url('../images/xsppsheadgrey.svg?1348834673') center top no-repeat, url('../images/xsppsbhairspikyboyblonde.svg?1348682005') center top no-repeat;
}

.hair-blonde .curlyafro {
  background: url('../images/xsppsfhaircurlyafroblonde.svg?1348681869') center top no-repeat, url('../images/xsppsheadgrey.svg?1348834673') center top no-repeat, url('../images/xsppsbhaircurlyafroblonde.svg?1348682005') center top no-repeat;
}

This is great, but as I have a total combination of 35 hair colours and hair styles, I still end up with way too many @includes.

On this page, it says SASS has an @each which can be used to loop through lists. There is a further example here. However, both these examples only show looping through 1 list. Is it possible to loop through two lists?

I have tried many variations of my code, but none seem to work. I thought the following would definitely work, but I just get an error message about $colour being undefined.

$hairstyle: (red, blonde, ltbrown);
$haircolour: (red, blonde, ltbrown);

    @each $hair in $haircolour, $colour in $haircolour {
    .hair-#{$colour} .#{$hair}  {
background:image-url("xsppsfhair#{$hair}#{$colour}.svg") center top no-repeat, 
image-url("xsppsheadgrey.svg") center top no-repeat, 
image-url("xsppsbhair#{$hair}#{$colour}.svg") center top no-repeat;
    }

    .girl.hair-#{$colour} #eyelash {
        background: image-url("xsppseyelash#{$colour}.svg") center top no-repeat;
    }
}

Could someone please give me some pointers as to what I am 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-06-12T03:49:24+00:00Added an answer on June 12, 2026 at 3:49 am

    What you need to do is create a loop inside the first loop (I’ve simplified a bit so it’s easier to see):

    @mixin style-matrix($colors, $styles) {
        @each $s in $styles {
            @each $c in $colors {
                .#{$s} .#{$c} {
                    background:image-url("xsppsfhair-#{$s}-#{$c}.svg");
                }
            }
        }
    }
    
    $colors: blonde, brunette, auburn;
    $styles: beehive, pixie, bob;
    @include style-matrix($colors, $styles);
    

    You get this output:

    .beehive .blonde {
      background: image-url("xsppsfhair-beehive-blonde.svg");
    }
    
    .beehive .brunette {
      background: image-url("xsppsfhair-beehive-brunette.svg");
    }
    
    .beehive .auburn {
      background: image-url("xsppsfhair-beehive-auburn.svg");
    }
    
    .pixie .blonde {
      background: image-url("xsppsfhair-pixie-blonde.svg");
    }
    
    .pixie .brunette {
      background: image-url("xsppsfhair-pixie-brunette.svg");
    }
    
    .pixie .auburn {
      background: image-url("xsppsfhair-pixie-auburn.svg");
    }
    
    .bob .blonde {
      background: image-url("xsppsfhair-bob-blonde.svg");
    }
    
    .bob .brunette {
      background: image-url("xsppsfhair-bob-brunette.svg");
    }
    
    .bob .auburn {
      background: image-url("xsppsfhair-bob-auburn.svg");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a div that unions CSS classes as such: <div id=tp class=ui-hidden-on-load ui-tablepicker
I have to create one table using XSLT and CSS. The table should look
How can I create equal height columns in CSS? All I have found searching
I have created a button CSS class that uses background images with different positions
I have created a custom style sheet that overrides the original CSS for my
I have a collection of PHP classes that can be instantiated traditionally using constructors.
I have been writing some code that creates a generic blog. Its features are
im using mvc framework and i have learned some techniques that help me with
I'm using ASP.NET Ajax with JQuery. I have a click event that adds/removes css
I have a task (for instance): create an HTML&CSS according to the given Jpg

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.