Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Negative Variables in LESS

Tags:

css

less

New to LESS, I am attempting to center a div using the following:

#form_block {
    display: block;
    position: absolute;
    @width: 800px;
    @height: 500px;
    width: @width;
    height: @height;
    top: 50%;
    left: 50%;
    margin-left: -@width/2 px;
    margin-top: -250px;

It seems like margin-top is set correctly since it the dimensions are explicitly there. But I can't seem to take the negative of a variable no matter how hard I try (ie. -(@width), -1 * @width, etc) Any ideas? It may just be a silly mistake.

like image 719
zhuyxn Avatar asked Feb 16 '13 23:02

zhuyxn


People also ask

Can a variable have a negative?

If you see a letter included in a mathematical equation, you are looking at what is referred to as a "variable." Variables are letters that are used to represent varying numerical amounts. Variables can be negative or positive in nature.

How do you know if a variable is negative?

To check if a value is a negative number, compare it to 0 , e.g. num < 0 . If the value to the left hand side of the less-than operator is not already a number, it will get converted to one and compared to 0 .


1 Answers

I had the same issue earlier today (with lessphp). Try:

margin-left: -(@width/2);

(without px)

And you should also round the value:

margin-left: -(round(@width/2));
like image 60
nice ass Avatar answered Sep 19 '22 10:09

nice ass