@@ -1585,18 +1585,22 @@ Functional Notations</h2>
15851585-->
15861586
15871587<h3 id="calc-notation">
1588- Mathematical Expressions: ''calc()'', ''min()'', and ''max ()''</h3>
1588+ Mathematical Expressions: ''calc()'', ''min()'', ''max()'', and ''clamp ()''</h3>
15891589
15901590 The <dfn export lt="math function">math functions</dfn> ,
1591- <dfn>calc()</dfn> , <dfn>min()</dfn> , and <dfn>max()</dfn> ,
1591+ <dfn>calc()</dfn> , <dfn>min()</dfn> , <dfn>max()</dfn> , and <dfn>clamp()</dfn>
15921592 allow mathematical expressions
15931593 with addition (''+'' ), subtraction (''-'' ), multiplication (''*'' ), and division (''/'' )
15941594 to be used as component values.
15951595 A ''calc()'' function represents the result of the mathematical calculation it contains,
15961596 using standard operator precedence rules;
15971597 a ''min()'' or ''max()'' function represents
15981598 the smallest (most negative) or largest (most positive), respectively,
1599- comma-separated calculation it contains.
1599+ comma-separated calculation it contains;
1600+ a ''clamp()'' function represents its central calculation,
1601+ clamped according to its min and max calculations
1602+ (given ''clamp(MIN, VAL, MAX)'' ,
1603+ it is resolved exactly identically to ''max(MIN, min(VAL, MAX))'' ).
16001604
16011605 A [=math function=] can be used wherever
16021606 <<length>> ,
@@ -1672,16 +1676,42 @@ Mathematical Expressions: ''calc()'', ''min()'', and ''max()''</h3>
16721676 </pre>
16731677 </div>
16741678
1679+ <div class=note>
1680+ Note that ''clamp()'' ,
1681+ matching CSS conventions elsewhere,
1682+ has its minimum value "win" over its maximum value
1683+ if the two are in the "wrong order".
1684+ That is, ''clamp(100px, ..., 50px)''
1685+ will resolve to ''100px'' ,
1686+ exceeding its stated "max" value.
1687+
1688+ If alternate resolution mechanics are desired
1689+ they can be achieved by combining ''clamp()'' with ''min()'' or ''max()'' :
1690+
1691+ : To have MAX win over MIN:
1692+ ::
1693+ ''clamp(min(MIN, MAX), VAL, MAX)'' .
1694+ If you want to avoid repeating the MAX calculation,
1695+ you can just reverse the nesting of functions that ''clamp()'' is defined against--
1696+ ''min(MAX, max(MIN, VAL))'' .
1697+
1698+ : To have MAX and MIN "swap" when they're in the wrong order:
1699+ ::
1700+ ''clamp(min(MIN, MAX), VAL, max(MIN, MAX))'' .
1701+ Unfortunately, there's no easy way to do this without repeating the MIN and MAX terms.
1702+ </div>
1703+
16751704
16761705<h4 id='calc-syntax'>
16771706Syntax</h4>
16781707
16791708 The syntax of a [=math function=] is:
16801709
16811710 <pre class='prod'>
1682- <<calc()>> = calc( <<calc-sum>> )
1683- <<min()>> = min( <<calc-sum>> # )
1684- <<max()>> = max( <<calc-sum>> # )
1711+ <<calc()>> = calc( <<calc-sum>> )
1712+ <<min()>> = min( <<calc-sum>> # )
1713+ <<max()>> = max( <<calc-sum>> # )
1714+ <<clamp()>> = clamp( <<calc-sum>> #{3} )
16851715 <dfn><calc-sum></dfn> = <<calc-product>> [ [ '+' | '-' ] <<calc-product>> ]*
16861716 <dfn><calc-product></dfn> = <<calc-value>> [ [ '*' | '/' ] <<calc-value>> ]*
16871717 <dfn><calc-value></dfn> = <<number>> | <<dimension>> | <<percentage>> | ( <<calc-sum>> )
@@ -1788,7 +1818,7 @@ Type Checking</h4>
17881818
17891819 * The [=CSSNumericValue/type=] of a ''calc()'' expression
17901820 is the [=CSSNumericValue/type=] of its contained expression.
1791- The [=CSSNumericValue/type=] of a ''min()'' or ''max ()'' expression
1821+ The [=CSSNumericValue/type=] of a ''min()'' , ''max()'' , or ''clamp ()'' expression
17921822 is the result of [=add two types|adding the types=]
17931823 of its comma-separated expressions.
17941824 If the result is failure,
0 commit comments