Mike Eng
Mike Eng

Reputation: 1681

How to reference the class present in an element in Sass or Less

I'm trying to use a CSS preprocessor to reduce some duplication when writing the code. In my HTML, these elements will only have one class. I want to go from something like

a.USA{background: url('images/USA.gif'};
a.EUR{background: url('images/EUR.gif'};
a.JPN{background: url('images/JPN.gif'};

to the following pseudo-code:

a.USA,a.EUR,a.JPN{
  background: url('images/[THE-NAME-OF-THE-ACTUAL-CLASS-USED].gif');
}

How could I do this in LESS or Sass (doesn't matter which)?

Upvotes: 1

Views: 118

Answers (1)

simialbi
simialbi

Reputation: 507

As Harry mentioned, the ouput would be the same. But its possible with sass. The example here is something you search: http://sass-lang.com/documentation/file.SASS_REFERENCE.html#each-directive

Upvotes: 2

Related Questions