Alex Rivera | Logout

concatenate values in less (css) without a space

Asked 2011-05-17T06:47:50.663
28

So I'm trying to make a LESS mixin which takes a number (degrees to rotate) and output the correct css to rotate the element. The problem is, I can't figure out a way to write both "270deg" and "3" (270/90) for IE. Here are the things i've tried:

.rotate(@rotation: 0) {
    @deg: deg;
    -webkit-transform: rotate(@rotation deg); // i can see why this doesn't work
    -moz-transform: rotate((@rotation)deg); // parens
    -o-transform: rotate(@rotation+deg); // variable-keyword concatenation
    transform: rotate(@rotation+@deg); // variable-variable concatenation

    // this is the reason I need @rotation to be just a number:
    filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=@rotation/90);
}

.someElement {
    .rotate(270)
}

For now i've just modified the compiler script so that it doesn't put a space between variable/keyword concatenation. I'd hope theres a better solution.

Edit
Report

1 Answer

3

Thank you cloudhead. Since the escaping for LESS PHP is a little different, this is what worked for me:

.rotation(@rotation:90){
  @degs: e("@{rotation}deg");
  @degs-ie: @rotation / 90;

  -webkit-transform: rotate(@degs);
  -moz-transform: rotate(@degs);
  transform: rotate(@degs);
  filter: e("progid:DXImageTransform.Microsoft.BasicImage(rotation=@{degs-ie})");
}
answered 2012-03-07T09:20:47.433

Your Answer