Question

I'm trying to make a mixin with multiple variables in LESS, but for some reason it's not working. I have this LESS:

.rgbabg(@r: 0, @g: 0, @b: 0, @a: .5) {
  @val: rgba(@r, @g, @b, @a);

  background: @val;
}

I call it like this:

.rgbabg(255, 0, 0, .5);

But I don't get any background on my element at all. Is my syntax ok?

Was it helpful?

Solution

Your syntax of your mixin is fine, and it compiles fine. I tried it out in my LESS converter and it's all good. I applied the rule to a page for an a tag selector:

a {
  .rgbabg(255);
}

And it outputs:

a {
  background: rgba(255, 0, 0, 0.5);
}

which colors my links just like it sounds like it should.

What version of LESS are you compiling with - what platform and version of the complier? I wouldn't recommend the Ruby compiler as I don't think it's kept up much anymore, and all the cool new features and support are on the Javascript less.js project. If you're doing it in PHP or .NET then you should check with those projects respectively.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top