@@ -529,6 +529,101 @@ <h5>The 'vm' unit</h5>
529529units. When the height or width of the viewport is changed, lengths
530530specified in the 'vm' unit are scaled proportionally.
531531
532+ < h4 > The 'calc' function</ h4 >
533+
534+ < p > The < dfn > calc(<expression>)</ dfn > function can be used wherever length values are allowed, with the syntax given below.
535+
536+ <!--
537+ The expression within the parethesis is computed at the same time as 'em' lengths are
538+ computed
539+ -->
540+
541+ < div class ="example ">
542+ < pre >
543+ section {
544+ float: left;
545+ margin: 1em; border: solid 1px;
546+ width: calc(100%/3 - 2*1em - 2*1px);
547+ }
548+ </ pre >
549+ </ div >
550+
551+ < div class ="example ">
552+ < pre >
553+ p {
554+ margin: calc(1rem - 2px) calc(1rem - 1px);
555+ border: solid transparent; border-width: 2px 1px;
556+ }
557+ </ pre >
558+ </ div >
559+
560+
561+ < p > The simple expression language of the 'calc()' function supports
562+ five arithmetic operators (+ and - have lowest precedence, *, /, and
563+ 'mod' have highest precedence) and parentheses.
564+
565+ < p > A value is ignored if a division by zero or other mathemathical
566+ errors occur in the calculation.
567+
568+ < div class ="example ">
569+ < p > In this example, the second declaration will be ignored due to a
570+ division by zero.
571+ < pre >
572+ p {
573+ margin: 1em;
574+ margin: calc(1em-2px) calc(1em/0)
575+ }
576+ </ pre >
577+ </ div >
578+
579+
580+ < p class =issue > Issue: At a later date new operators such as min/max, conditionals, new constants, division by length units etc. may be added.
581+
582+
583+ < p > The expression language is defined by 'length-expression' below:
584+
585+ < pre >
586+ <length> := calc( <length-expression> ) | <atomic-length>
587+
588+ <length-expression> := <length-additive-expression>
589+
590+ <length-additive-expression> :=
591+ <length-multiplicative-expression> |
592+ <length-additive-expression> S* '+' S* <length-multiplicative-expression> |
593+ <length-additive-expression> S* '-' S* <length-multiplicative-expression>
594+
595+ <length-multiplicative-expression>
596+ <length-term> |
597+ <length-multiplicative-expression> S* '*' S* <number-term> |
598+ <number-multiplicative-expression> S* '*' S* <length-term> |
599+ <length-multiplicative-expression> S* '/' S* <number-term> |
600+ <length-multiplicative-expression> S* 'mod' S* <number-term>
601+
602+ <length-term> := '(' <length-expression> ')' | <atomic-length>
603+
604+ <number-additive-expression> :=
605+ <number-multiplicative-expression> |
606+ <number-additive-expression> S* '+' S* <number-multiplicative-expression> |
607+ <number-additive-expression> S* '-' S* <number-multiplicative-expression>
608+
609+ <number-multiplicative-expression> :=
610+ <number-term> |
611+ <length-multiplicative-expression> S* '/' S* <length-term> |
612+ <length-multiplicative-expression> S* 'mod' S* <length-term>
613+
614+ <number-term> := '(' <number-additive-expression> ')' | <number>
615+
616+ <atomic-length> := <number> <length-unit>
617+ </ pre >
618+
619+ < div class ="note "> Note that 'mod' is used instead of '%' for modulus since it is very easy to
620+ get confused about whether '%' is acting as a unit or an operator. At
621+ least with 'mod' it always causes a parse error — invalid unit — in the
622+ otherwise ambiguous cases.
623+ </ div >
624+
625+
626+
532627
533628< h3 > <fraction></ h3 >
534629
@@ -1000,99 +1095,6 @@ <h4>The 'counter' function</h4>
10001095</div>
10011096-->
10021097
1003- < h4 > The 'calc' function</ h4 >
1004-
1005- < p > The < dfn > calc(<expression>)</ dfn > function can be used wherever length values are allowed, with the syntax given below.
1006-
1007- <!--
1008- The expression within the parethesis is computed at the same time as 'em' lengths are
1009- computed
1010- -->
1011-
1012- < div class ="example ">
1013- < pre >
1014- section {
1015- float: left;
1016- margin: 1em; border: solid 1px;
1017- width: calc(100%/3 - 2*1em - 2*1px);
1018- }
1019- </ pre >
1020- </ div >
1021-
1022- < div class ="example ">
1023- < pre >
1024- p {
1025- margin: calc(1rem - 2px) calc(1rem - 1px);
1026- border: solid transparent; border-width: 2px 1px;
1027- }
1028- </ pre >
1029- </ div >
1030-
1031-
1032- < p > The simple expression language of the 'calc()' function supports
1033- five arithmetic operators (+ and - have lowest precedence, *, /, and
1034- 'mod' have highest precedence) and parentheses.
1035-
1036- < p > A value is ignored if a division by zero or other mathemathical
1037- errors occur in the calculation.
1038-
1039- < div class ="example ">
1040- < p > In this example, the second declaration will be ignored due to a
1041- division by zero.
1042- < pre >
1043- p {
1044- margin: 1em;
1045- margin: calc(1em-2px) calc(1em/0)
1046- }
1047- </ pre >
1048- </ div >
1049-
1050-
1051- < p class =issue > Issue: At a later date new operators such as min/max, conditionals, new constants, division by length units etc. may be added.
1052-
1053-
1054- < p > The expression language is defined by 'length-expression' below:
1055-
1056- < pre >
1057- <length> := calc( <length-expression> ) | <atomic-length>
1058-
1059- <length-expression> := <length-additive-expression>
1060-
1061- <length-additive-expression> :=
1062- <length-multiplicative-expression> |
1063- <length-additive-expression> S* '+' S* <length-multiplicative-expression> |
1064- <length-additive-expression> S* '-' S* <length-multiplicative-expression>
1065-
1066- <length-multiplicative-expression>
1067- <length-term> |
1068- <length-multiplicative-expression> S* '*' S* <number-term> |
1069- <number-multiplicative-expression> S* '*' S* <length-term> |
1070- <length-multiplicative-expression> S* '/' S* <number-term> |
1071- <length-multiplicative-expression> S* 'mod' S* <number-term>
1072-
1073- <length-term> := '(' <length-expression> ')' | <atomic-length>
1074-
1075- <number-additive-expression> :=
1076- <number-multiplicative-expression> |
1077- <number-additive-expression> S* '+' S* <number-multiplicative-expression> |
1078- <number-additive-expression> S* '-' S* <number-multiplicative-expression>
1079-
1080- <number-multiplicative-expression> :=
1081- <number-term> |
1082- <length-multiplicative-expression> S* '/' S* <length-term> |
1083- <length-multiplicative-expression> S* 'mod' S* <length-term>
1084-
1085- <number-term> := '(' <number-additive-expression> ')' | <number>
1086-
1087- <atomic-length> := <number> <length-unit>
1088- </ pre >
1089-
1090- < div class ="note "> Note that 'mod' is used instead of '%' for modulus since it is very easy to
1091- get confused about whether '%' is acting as a unit or an operator. At
1092- least with 'mod' it always causes a parse error — invalid unit — in the
1093- otherwise ambiguous cases.
1094- </ div >
1095-
10961098
10971099
10981100< h3 > Special cases</ h3 >
0 commit comments