P
P
Pavel Gogolinsky2016-09-20 09:40:41
Sass
Pavel Gogolinsky, 2016-09-20 09:40:41

Is it possible to use the element ID as a variable?

You need to dynamically assign a background image depending on the ID. Something like this:

@each .class-elementa {
    background: url(/images/#{$id-elementa}.jpg)
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex Glebov, 2016-09-20
@SkiperX

@each $name in 'save' 'cancel' 'help' {
    .icon-#{$name} {
        background-image: url('/images/#{$name}.png');
    }
}

at the exit
.icon-save {
  background-image: url("/images/save.png");
}

.icon-cancel {
  background-image: url("/images/cancel.png");
}

.icon-help {
  background-image: url("/images/help.png");
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question