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.
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.
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 .
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));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With