search

Home  >  Q&A  >  body text

Why CSS Calc() function only requires spaces before and after the "+" or "-" operator

<p>For example: <code>calc(10px 2px);</code> is correct but <code>calc(10px 2px);</code> gives an error or <code>calc(10px - 2px);</code> is c or rect but <code>calc(10px -2px);</code> gives an error or. However, this does not apply to other operations</p>
P粉004287665P粉004287665459 days ago563

reply all(1)I'll reply

  • P粉691461301

    P粉6914613012023-09-01 09:03:22

    For the operator, the operation may be slightly more complicated than calc(10px 2px);. I mean something like calc(5px -1px); is actually more complex and impossible to be calc(5px -1px);.

    For the - operator, how does CSS know whether - is the minus operator or part of a negative number? I mean logically.

    Additionally, whitespace makes code easier for humans to read.

    Learn more about CSS calc() function in the documentation.

    reply
    0
  • Cancelreply