Skip to content

Commit ec87d63

Browse files
committed
[css-values] Add an example about preserving percentages in calc().
1 parent 2a4de87 commit ec87d63

File tree

2 files changed

+50
-4
lines changed

2 files changed

+50
-4
lines changed

css-values/Overview.html

+28-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
rel=dcterms.rights>
1212
<meta content="CSS Values and Units Module Level 3" name=dcterms.title>
1313
<meta content=text name=dcterms.type>
14-
<meta content=2013-12-06 name=dcterms.date>
14+
<meta content=2013-12-18 name=dcterms.date>
1515
<meta content="Håkon Wium Lie" name=dcterms.creator>
1616
<meta content="Tab Atkins" name=dcterms.creator>
1717
<meta content="Elika J. Etemad" name=dcterms.creator>
@@ -42,11 +42,11 @@
4242
<h1 class=p-name>CSS Values and Units Module Level 3</h1>
4343

4444
<h2 class="no-num no-toc">Editor's Draft <span class=dt-updated><span
45-
class=value title=20131206> 6 December 2013</span></span></h2>
45+
class=value title=20131218>18 December 2013</span></span></h2>
4646

4747
<dl>
4848
<dt>This version:</dt>
49-
<!--<dd><a class="u-url" href="http://dev.w3.org/csswg/css-values/">http://www.w3.org/TR/2013/CR-css3-values-20131206/</a></dd>-->
49+
<!--<dd><a class="u-url" href="http://dev.w3.org/csswg/css-values/">http://www.w3.org/TR/2013/CR-css3-values-20131218/</a></dd>-->
5050

5151
<dd><a class=u-url
5252
href="http://dev.w3.org/csswg/css-values/">http://dev.w3.org/csswg/css-values/</a>
@@ -1639,7 +1639,31 @@ <h4 id=calc-computed-value><span class=secno>8.1.3. </span> Computed Value</h4>
16391639
<p class=note> Thus, the computed value of a ‘<a href="#calc"><code
16401640
class=css>calc()</code></a>’ expression can be represented as either a
16411641
number or a tuple of a dimension and a percentage.
1642-
<!-- http://lists.w3.org/Archives/Public/www-style/2010May/0001.html
1642+
1643+
<div class=example>
1644+
<p> For example, ‘<code class=property>background-position</code>’ has
1645+
special behavior for percentage values, different from lengths:
1646+
1647+
<pre>
1648+
.foo {
1649+
width: 200px;
1650+
background-image: url(bg.png);
1651+
background-position: left 50%;
1652+
/* different than: */
1653+
background-position: left 100px;
1654+
/* despite 50% of 200px being 100px */
1655+
}</pre>
1656+
1657+
<p> Due to this, ‘<code class=property>background-position</code>
1658+
preserves the percentage in a ‘<a href="#calc"><code
1659+
class=css>calc()</code></a>’ rather than resolving it directly into a
1660+
length, so that an expression like ‘<code
1661+
class=css>background-position: left calc(50% + 20px)</code>’ properly
1662+
centers the background and then shifts it ‘<code
1663+
class=css>20px</code>’ to the right, rather than placing its <em>left
1664+
edge</em> 20px off of center.
1665+
</div>
1666+
<!-- http://lists.w3.org/Archives/Public/www-style/2010May/0001.html
16431667
This has notes on how we should handle things when calc() is extended to
16441668
handle unit mult/div. Related to this is <unit>mod<unit>, which can return
16451669
0 and thus introduce computed-time division-by-zero. -->

css-values/Overview.src.html

+22
Original file line numberDiff line numberDiff line change
@@ -1171,6 +1171,28 @@ <h4 id='calc-computed-value'>
11711171
as either a number
11721172
or a tuple of a dimension and a percentage.
11731173

1174+
<div class='example'>
1175+
<p>
1176+
For example, 'background-position' has special behavior for percentage values, different from lengths:
1177+
1178+
<pre>
1179+
.foo {
1180+
width: 200px;
1181+
background-image: url(bg.png);
1182+
background-position: left 50%;
1183+
/* different than: */
1184+
background-position: left 100px;
1185+
/* despite 50% of 200px being 100px */
1186+
}</pre>
1187+
1188+
<p>
1189+
Due to this, 'background-position' preserves the percentage in a ''calc()''
1190+
rather than resolving it directly into a length,
1191+
so that an expression like ''background-position: left calc(50% + 20px)''
1192+
properly centers the background and then shifts it ''20px'' to the right,
1193+
rather than placing its <em>left edge</em> 20px off of center.
1194+
</div>
1195+
11741196
<!-- http://lists.w3.org/Archives/Public/www-style/2010May/0001.html
11751197
This has notes on how we should handle things when calc() is extended to
11761198
handle unit mult/div. Related to this is <unit>mod<unit>, which can return

0 commit comments

Comments
 (0)