2

How should we write in .less to obtain

left: calc(50% - 38px);

I have

@myWidth: 38px;
left: calc(50% - @myWidth);

I obtain

left: calc(12%); // ?? > (50-38) = 12%
serge
  • 13,940
  • 35
  • 121
  • 205

1 Answers1

1

LESS makes calculations using the first unit of measurement it encounters. Since you don't want LESS to calculate the expression, wrap it in a string.

Pen - click view compiled in the CSS panel

left: calc(~'50% - 38px');

@myWidth: 38px;
left: calc(~'50% - @{myWidth}');
Ori Drori
  • 183,571
  • 29
  • 224
  • 209