A
A
Andrey Khokhlov2014-09-03 19:05:45
css
Andrey Khokhlov, 2014-09-03 19:05:45

Is it possible to use the value of the less variable as the name of another variable and mixin?

I do not paint the question in more detail, since there will be too many beeches. I'm trying to do what they talked about at codefest 2gis: www.slideshare.net/codefest/codefest-2014-2
At the same time, I only have this presentation, and that's it - no video, nothing else.
Stages with generation of base64, png-sprite and css are completed.
Now I would like to collect everything in a single mixin.
For starters, the version with the base64 icon and no fallback for ie8.
This mixin generates the required CSS, but for the "icons_zoom" icon:

.bg-icon(@filename) {
  .data-icons_zoom; // берем base64 из сгенерированного css
  background-repeat: no-repeat;
  .sprite-width(@icons_zoom); // берем размеры иконки из css для спрайта (больше неоткуда)
  .sprite-height(@icons_zoom);
}

If what I want worked, it would look like this:
.bg-icon(@filename) {
  [email protected];
  background-repeat: no-repeat;
  .sprite-width(@@filename);
  .sprite-height(@@filename);
}

The question is - is it possible (and if so, how) to use the value of the variable passed to the mixin in this way?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nodge, 2014-09-11
@andrhohlov

@@filename - you can.
Mixins can be done via guards:

@sprite1: 100px;
@sprite2: 200px;

.data-sprite(@filename) when (@filename = sprite1) {
  background: red;
}

.data-sprite(@filename) when (@filename = sprite2) {
  background: green;
}

.sprite-width(@width) {
  width: @width;
}

.sprite-height(@width) {
  height: @width;
}

.bg-icon(@filename) {
  .data-sprite(@filename);
  background-repeat: no-repeat;
  .sprite-width(@@filename);
  .sprite-height(@@filename);
}

html {
  .bg-icon(sprite1);
}

body {
  .bg-icon(sprite2);
}

Example: jsbin.com/cipafe/1/edit

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question