CSS calc not working LESS

Sometimes LESS screws an expression inside calc(). To avoid this situation, I do a very basic trick.

Let’s say I want to implement the following to keep a div of 510px width at the center of something.

left: calc(50% - 255px);

Now, the trick is, instead of using calc(), I just use left 50% and add a negative margin to pull it back a half of it’s width (255px, in this case).

margin-left: -255px;
left: 50%;

Dumb and easy, right?
Hope this trick will save someone’s time!

1 Comment

Leave a Comment

Your email address will not be published. Required fields are marked *