Skip to content

Commit 110f679

Browse files
authored
docs(CSS): Clarify use of calc() function with percentages (mdn#22896)
Fixes mdn#22805
1 parent b051dcb commit 110f679

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

files/en-us/web/css/calc/index.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ browser-compat: css.types.calc
1717

1818
{{CSSRef}}
1919

20-
The **`calc()`** [CSS](/en-US/docs/Web/CSS) [function](/en-US/docs/Web/CSS/CSS_Functions) lets you perform calculations when specifying CSS property values. It can be used anywhere a {{cssxref("<length>")}}, {{cssxref("<frequency>")}}, {{cssxref("<angle>")}}, {{cssxref("<time>")}}, {{cssxref("<percentage>")}}, {{cssxref("<number>")}}, or {{cssxref("<integer>")}} is allowed.
20+
The **`calc()`** [CSS](/en-US/docs/Web/CSS) [function](/en-US/docs/Web/CSS/CSS_Functions) lets you perform calculations when specifying CSS property values. It can be used with {{cssxref("<length>")}}, {{cssxref("<frequency>")}}, {{cssxref("<angle>")}}, {{cssxref("<time>")}}, {{cssxref("<percentage>")}}, {{cssxref("<number>")}}, or {{cssxref("<integer>")}} values.
2121

2222
{{EmbedInteractiveExample("pages/css/function-calc.html")}}
2323

@@ -43,12 +43,13 @@ The operands in the expression may be any {{cssxref("<length>")}} syntax v
4343

4444
### Notes
4545

46-
- The `+` and `-` operators **must be surrounded by {{Glossary("whitespace")}}**. For instance, `calc(50% -8px)` will be parsed as a percentage followed by a negative length — an invalid expression — while `calc(50% - 8px)` is a percentage followed by a subtraction operator and a length. Likewise, `calc(8px + -50%)` is treated as a length followed by an addition operator and a negative percentage.
47-
- The `*` and `/` operators do not require whitespace, but adding it for consistency is both allowed and recommended.
46+
- The `+` and `-` operators **must be surrounded by {{Glossary("whitespace")}}**. For instance, `calc(50% -8px)` will be parsed as "a percentage followed by a negative length"which is an invalid expression — while `calc(50% - 8px)` is "a percentage followed by a subtraction operator and a length". Likewise, `calc(8px + -50%)` is treated as "a length followed by an addition operator and a negative percentage".
47+
- The `*` and `/` operators do not require whitespace, but adding it for consistency is recommended.
4848
- Division by zero results in an error being generated by the HTML parser.
4949
- Math expressions involving percentages for widths and heights on table columns, table column groups, table rows, table row groups, and table cells in both auto and fixed layout tables _may_ be treated as if `auto` had been specified.
5050
- It is permitted to nest `calc()` functions, in which case the inner ones are treated as simple parentheses.
5151
- For lengths, you can't use `0` to mean `0px` (or another length unit); instead, you must use the version with the unit: `margin-top: calc(0px + 20px);` is valid, while `margin-top: calc(0 + 20px);` is invalid.
52+
- The `calc()` function cannot directly substitute the numeric value for percentage types; for instance `calc(100 / 4)%` is invalid, while `calc(100% / 4)` is valid.
5253

5354
### Formal syntax
5455

0 commit comments

Comments
 (0)