@@ -1585,18 +1585,22 @@ Functional Notations</h2>
1585
1585
-->
1586
1586
1587
1587
<h3 id="calc-notation">
1588
- Mathematical Expressions: ''calc()'', ''min()'', and ''max ()''</h3>
1588
+ Mathematical Expressions: ''calc()'', ''min()'', ''max()'', and ''clamp ()''</h3>
1589
1589
1590
1590
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>
1592
1592
allow mathematical expressions
1593
1593
with addition (''+'' ), subtraction (''-'' ), multiplication (''*'' ), and division (''/'' )
1594
1594
to be used as component values.
1595
1595
A ''calc()'' function represents the result of the mathematical calculation it contains,
1596
1596
using standard operator precedence rules;
1597
1597
a ''min()'' or ''max()'' function represents
1598
1598
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))'' ).
1600
1604
1601
1605
A [=math function=] can be used wherever
1602
1606
<<length>> ,
@@ -1672,16 +1676,42 @@ Mathematical Expressions: ''calc()'', ''min()'', and ''max()''</h3>
1672
1676
</pre>
1673
1677
</div>
1674
1678
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
+
1675
1704
1676
1705
<h4 id='calc-syntax'>
1677
1706
Syntax</h4>
1678
1707
1679
1708
The syntax of a [=math function=] is:
1680
1709
1681
1710
<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} )
1685
1715
<dfn><calc-sum></dfn> = <<calc-product>> [ [ '+' | '-' ] <<calc-product>> ]*
1686
1716
<dfn><calc-product></dfn> = <<calc-value>> [ [ '*' | '/' ] <<calc-value>> ]*
1687
1717
<dfn><calc-value></dfn> = <<number>> | <<dimension>> | <<percentage>> | ( <<calc-sum>> )
@@ -1788,7 +1818,7 @@ Type Checking</h4>
1788
1818
1789
1819
* The [=CSSNumericValue/type=] of a ''calc()'' expression
1790
1820
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
1792
1822
is the result of [=add two types|adding the types=]
1793
1823
of its comma-separated expressions.
1794
1824
If the result is failure,
0 commit comments