Calc() Function Woes: Why It's Not Working
Your calc(100vw/4) function is functioning as expected, but the others are not because of a crucial element: spaces.
The CSS calc() function requires spaces between its operators. Common errors include omitting these spaces, leading to invalid expressions.
For instance, the expression calc(100vw/4-(10-4)) is invalid because of the missing space between "-" and the parentheses. Instead, it should be: calc(100vw/4 - (10 - 4)).
Nested Calc() Functions
You can nest calc() functions as many times as needed, but it functions the same way as parentheses. For example:
<code class="css">calc(100vw/4 - calc(10px - 4px))</code>
Is equivalent to:
<code class="css">calc(100vw/4 - (10px - 4px))</code>
Example
Here's an example of a nested calc() function:
<code class="css">.one { width: calc(100% - 150px); margin-top: calc(20px + calc(40px * 2)); height: calc(100px - 10px); padding: calc(5% + 10px) calc(5% - 5px); }</code>
In this example, the margin-top property uses a nested calc() function to add 20px to the result of multiplying 40px by 2.
The above is the detailed content of Why Isn\'t My calc() Function Working?. For more information, please follow other related articles on the PHP Chinese website!