Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS/LESS: Calc() using percentages minus pixels not evaluating correctly [duplicate]

Tags:

css

dynamic

less

This is a question that has been asked several times before, but none of the answers I have found seem to work in my case. I have 3 buttons and I am trying to evaluate their width as follows:

.num-buttons-3 {
    width: calc((100% - 40px)/3);
}

This always evaluates in my browser (Chrome) as 20%, which is (100% - 40%)/3.

I have tried numerous suggested alternatives to get this to evaluate correctly, such as:

.num-buttons-3 {
   width: calc((~'100% - 40px')/3);
}

.num-buttons-3 {
@marg: 40px;
width: calc((~'100% - @{marg}')/3);
}

Is therer another CSS or LESS solution I can try?

like image 573
MDalt Avatar asked Dec 04 '15 10:12

MDalt


Video Answer


1 Answers

Found an answer on this. Escaping the entire calc function is an option that seems to work:

width: ~"calc(((100% - 40px)/3))";
like image 109
MDalt Avatar answered Jan 03 '23 10:01

MDalt