|
92 | 92 | <h1 class="p-name no-ref" id="title">CSS Values and Units Module Level 3</h1> |
93 | 93 |
|
94 | 94 | <h2 class="no-num no-toc no-ref heading settled" id="subtitle"><span class="content">Editor’s Draft, |
95 | | - <time class="dt-updated" datetime="2015-06-08">8 June 2015</time></span></h2> |
| 95 | + <time class="dt-updated" datetime="2015-06-25">25 June 2015</time></span></h2> |
96 | 96 |
|
97 | 97 | <div data-fill-with="spec-metadata"> |
98 | 98 | <dl> |
@@ -454,6 +454,8 @@ <h2 class="no-num no-toc no-ref heading settled" id="contents"><span class="cont |
454 | 454 | Computed Value</span></a> |
455 | 455 | <li><a href="#calc-range"><span class="secno">8.1.4</span> <span class="content"> |
456 | 456 | Range Checking</span></a> |
| 457 | + <li><a href="#calc-serialize"><span class="secno">8.1.5</span> <span class="content"> |
| 458 | +Serialization</span></a> |
457 | 459 | </ul> |
458 | 460 | <li><a href="#toggle-notation"><span class="secno">8.2</span> <span class="content"> |
459 | 461 | Toggling Between Values: <span class="css">toggle()</span></span></a> |
@@ -2687,6 +2689,72 @@ <h4 class="heading settled" data-level="8.1.4" id="calc-range"><span class="secn |
2687 | 2689 | </div> |
2688 | 2690 |
|
2689 | 2691 |
|
| 2692 | + <h4 class="heading settled" data-level="8.1.5" id="calc-serialize"><span class="secno">8.1.5. </span><span class="content"> |
| 2693 | +Serialization</span><a class="self-link" href="#calc-serialize"></a></h4> |
| 2694 | + |
| 2695 | + |
| 2696 | + <p>To serialize a <a class="css" data-link-type="maybe" href="#funcdef-calc">calc()</a> value:</p> |
| 2697 | + |
| 2698 | + |
| 2699 | + <ol> |
| 2700 | + <li data-md=""> |
| 2701 | + <p>Simplify the expression by |
| 2702 | +resolving all multiplications and divisions, |
| 2703 | +and combining compatible units. |
| 2704 | +(Which units are compatible can vary based on what stage of the value computation pipeline it’s in. |
| 2705 | +For example, as a specified value, <span class="css">px</span> and <span class="css">em</span> are incompatible; |
| 2706 | +as a computed value, they’re compatible.)</p> |
| 2707 | + |
| 2708 | + |
| 2709 | + |
| 2710 | + <p>The result must be a summation of unique incompatible units. |
| 2711 | +(Terms with a value of zero <strong>must</strong> be preserved in this summation.)</p> |
| 2712 | + |
| 2713 | + |
| 2714 | + |
| 2715 | + <li data-md=""> |
| 2716 | + <p>If the result is a single value, |
| 2717 | +serialize as that value, |
| 2718 | +discarding the <a class="css" data-link-type="maybe" href="#funcdef-calc">calc()</a> wrapper.</p> |
| 2719 | + |
| 2720 | + |
| 2721 | + |
| 2722 | + <li data-md=""> |
| 2723 | + <p>Otherwise, serialize as a <a class="css" data-link-type="maybe" href="#funcdef-calc">calc()</a> containing the summation, |
| 2724 | +with the units ordered <a data-link-type="dfn" href="http://dom.spec.whatwg.org/#ascii-case_insensitive">ASCII case-insensitive</a> alphabetically, |
| 2725 | +numbers coming before all units, |
| 2726 | +and percentages coming after all units.</p> |
| 2727 | + |
| 2728 | +</ol> |
| 2729 | + |
| 2730 | + <div class="example" id="example-65075dff"><a class="self-link" href="#example-65075dff"></a> |
| 2731 | + For example, <span class="css">calc(20px + 30px)</span> would first simplify to a single <span class="css">px</span> value, |
| 2732 | + then serialize as just <span class="css">50px</span>. |
| 2733 | + |
| 2734 | + |
| 2735 | + <p>A value like <span class="css">calc(20px + 0%)</span> would serialize as <span class="css">calc(20px + 0%)</span>, |
| 2736 | + maintaining both terms in the serialized value. |
| 2737 | + (It’s important to maintain zero-valued terms, |
| 2738 | + so the <a class="css" data-link-type="maybe" href="#funcdef-calc">calc()</a> doesn’t suddenly "change shape" in the middle of a transition |
| 2739 | + when one of the values happens to have a zero value temporarily. |
| 2740 | + This also removes the need to "pick a unit" when all the terms are zero.)</p> |
| 2741 | + |
| 2742 | + |
| 2743 | + |
| 2744 | + <p>A value like <span class="css">calc(20px + 2em)</span> would serialize as <span class="css">calc(2em + 20px)</span> as a specified value |
| 2745 | + (maintaining both units as they’re incompatible at specified-value time, |
| 2746 | + but sorting them alphabetically), |
| 2747 | + or as something like <span class="css">52px</span> as a computed value |
| 2748 | + (<span class="css">em</span> values are converted to absolute lengths at computed-value time, |
| 2749 | + so assuming <span class="css">1em</span> = <span class="css">16px</span>, |
| 2750 | + they combine into <span class="css">52px</span>, |
| 2751 | + which then drops the <a class="css" data-link-type="maybe" href="#funcdef-calc">calc()</a> wrapper.)</p> |
| 2752 | + |
| 2753 | + |
| 2754 | + </div> |
| 2755 | + |
| 2756 | + |
| 2757 | + |
2690 | 2758 | <h3 class="heading settled" data-level="8.2" id="toggle-notation"><span class="secno">8.2. </span><span class="content"> |
2691 | 2759 | Toggling Between Values: <a class="css" data-link-type="maybe" href="#funcdef-toggle">toggle()</a></span><a class="self-link" href="#toggle-notation"></a></h3> |
2692 | 2760 |
|
|
0 commit comments