-
Notifications
You must be signed in to change notification settings - Fork 790
Expand file tree
/
Copy pathOverview.src.html
More file actions
519 lines (428 loc) · 38.8 KB
/
Overview.src.html
File metadata and controls
519 lines (428 loc) · 38.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>CSS Image Values Module Level 3</title>
<link rel="stylesheet" type="text/css" href="../default.css">
<link rel="stylesheet" type="text/css" href="http://www.w3.org/StyleSheets/TR/W3C-ED">
</head>
<body>
<div class="head">
<!--logo-->
<h1>CSS Image Values Module Level 3</h1>
<h2 class="no-num no-toc">[LONGSTATUS] [DATE]</h2>
<dl>
<dt>This version:</dt>
<!-- <dd><a href="http://www.w3.org/TR/[YEAR]/CR-css3-images-[CDATE]/">http://www.w3.org/TR/[YEAR]/CR-css3-images-[CDATE]/</a></dd> -->
<dd><a href="http://dev.w3.org/csswg/css3-images/">http://dev.w3.org/csswg/css3-images/</a>
<!-- <dt>Latest version:</dt>
<dd><a href="http://www.w3.org/TR/css3-images/">http://www.w3.org/TR/css3-images/</a></dd>
<dt>Previous version:</dt>
<dd><a href="http://www.w3.org/TR/2008/CR-css3-namespace-20080523/">http://www.w3.org/TR/2008/CR-css3-namespace-20080523/</a></dd> -->
<dt>Editor:</dt>
<dd><a href="http://fantasai.inkedblade.net/contact">Elika J. Etemad</a></dd>
<dd><a href="http://www.xanthir.com/contact">Tab Atkins Jr.</a></dd>
</dl>
<!--begin-copyright-->
<p>[Here will be included the file "../copyright.inc"]</p>
<!--end-copyright-->
<hr title="Separator for header">
</div>
<h2 class="no-num no-toc" id="abstract">Abstract</h2>
<p>This CSS Image Values and Replaced Content module has two parts:
First, it defines the syntax for <image> values in CSS.
<image> values can be a single URI to an image, a list of
URIs denoting a series of fallbacks, sprites (image slices), or
gradients. Second, it defines properties used to control the
interaction of replaced content and the CSS layout algorithms.
These properties can affect the used image resolution for bitmaps,
the replaced object's orientation, and whether and how to preserve
the object's aspect ratio.</p>
<h2 class="no-num no-toc" id="status">Status of this document</h2>
<!--status-->
<h2 class="no-num no-toc" id="contents">Table of contents</h2>
<!--toc-->
<div>
<h2 id="intro">Introduction</h2>
<p><em>This section is non-normative.</em></p>
<p>In CSS Levels 1 and 2, image values, such as those used in the
'background-image' property, could only be given by a single URI
value. This module introduces additional notations that allow a
2D image to be given as a list of URIs denoting fallbacks, as a
slice of a larger image (sprite), and as a gradient.</p>
</div>
<div>
<h2 id="conformance">Conformance</h2>
<p>A document or implementation cannot conform to CSS Image Values Level 3
alone, but can claim conformance to CSS Image Values Level 3 if it satisfies
the conformance requirements in this specification when implementing CSS or
another host language that normatively references this specification.</p>
<p>Conformance to CSS Namespaces is defined for two classes:
<dl>
<dt><dfn>style sheet</dfn></dt>
<dd>A <a href="http://www.w3.org/TR/CSS21/conform.html#style-sheet">CSS style
sheet</a> (or a complete unit of another host language that normatively
references CSS Namespaces).
<dt><dfn>interpreter</dfn></dt>
<dd>Someone or something that interprets the semantics of a style sheet.
(CSS <a href="http://www.w3.org/TR/CSS21/conform.html#user-agent">user
agents</a> fall under this category.)</dd>
</dl>
<p>The conformance requirements are expressed with a combination of
descriptive assertions and RFC 2119 terminology. The key words "MUST",
"MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT",
"RECOMMENDED", "MAY", and "OPTIONAL" in the normative parts of this
document are to be interpreted as described in RFC 2119.
However, for readability, these words do not appear in all uppercase
letters in this specification. All of the text of this specification is
normative except sections explicitly marked as non-normative, examples,
and notes. [[!RFC2119]]</p>
<p>Examples in this specification are introduced with the words "for example"
or are set apart from the normative text with <code>class="example"</code>,
like this:
<div class="example">
<p>This is an example of an informative example.</p>
</div>
<p>Informative notes begin with the word "Note" and are set apart from the
normative text with <code>class="note"</code>, like this:
<p class="note">Note, this is an informative note.</p>
</div>
<div>
<h2 id="image">Image Values: the <image> value type</h2>
<p>The <image> value type denotes a 2D image. It is defined as
<pre class="prod"><dfn><image></dfn> = <url> | <sprite> | <image-list> | <linear-gradient> | <radial-gradient></pre>
<p>Image values can be used in many CSS properties, including the
'background-image', 'list-style-image', 'cursor' properties [[!CSS21]].
</div>
<div>
<h2 id="url">Image References and Image Slices: the ''url()'' notation</h2>
<p>The simplest way to indicate an image is to reference an image file
by URI. This is done with the
<a href="http://www.w3.org/TR/CSS21/syndata.html#uri">''url()'' notation</a>,
defined in [[!CSS21]].
<div class="example">
<p>In the example below, a background image is specified with ''url()''
syntax:</p>
<pre>background-image: url(wavy.png);</pre>
</div>
<p>A portion of an image may be referenced (clipped out and used as a
standalone image) by use of fragment identifiers.
<span class='issue'>Need a spec to reference here. Expecting to get one from
<a href="http://www.w3.org/2008/WebVideo/Fragments/">Media Fragments WG</a>.</span>
<div class="example">
<p>For example,</p>
<pre>background-image: url('logos.png#xywh=10,30,60,20')</pre>
<p>uses the 60 pixel by 20 pixel rectangle of <code>logos.png</code> beginning
at the point 10 pixels in from the left, 30 pixels down from the top.
<p class="note">Note that quotation marks are required here, because
unquoted commas are not allowed in ''url()'' syntax.</p>
</div>
</div>
<div>
<h2 id="image-notation">Image Fallbacks: the ''image()'' notation</h2>
<p>The ''image()'' notation allows an author to specify multiple images,
each one a fallback for the previous. The UA must use only the first image
that it can load and display. The syntax for ''image()'' is defined as
<pre class="prod"><dfn><image-list></dfn> = <!--
-->image( [ <image-decl> , ]* [ <image-decl> ] [ or <color> ]? )</pre>
<p>where <image-decl> is given by
<pre class="prod"><dfn><image-decl></dfn> = <!--
-->[ <string> | <url-token> ] [ snap? && <resolution> ]?</pre>
<p><url-token> is given as <code>[!#$%&*-~]|{nonascii}|{escape}</code>
(i.e. the contents of ''url()'') using the productions in the
<a href="http://www.w3.org/TR/CSS21/syndata.html#tokenization">CSS2.1 tokenization</a>.
<strong>The <url-token> must not contain unescaped brackets, commas,
white space characters, single quotes (') or double quotes (");
if it does the ''image()'' containing it is invalid.</strong>
<p>Each string or url-token represents the URI of an image. If a resolution
is given, then the image must be rendered at the specified resolution. If the
''snap'' keyword is also specified, and the image is a raster image, then the
image must be rendered at the resolution closest to the specified resolution
that would result in no pixel rounding. <span class="issue">I don't think
"no pixel rounding" is the right terminology here... basically we want to
avoid blurry images.</span></p>
<p>The optional color at the end of the list is the <dfn>fallback color</dfn>.
It is used if, and only if, none of the images can be loaded and displayed
(e.g. because they are in unsupported formats, or cannot be found, or are
corrupted in some way, or because image loading is disabled in the UA). It
is treated as a single-color image with no intrinsic dimensions.
<div class="example">
<p>For example, the rule below would tell the UA to load ''wavy.svg'' if
it can; failing that to load ''wavy.png'' and display it at 150dpi;
failing that to display ''wavy.gif''; and finally, if none of the images
can be loaded and displayed, to use the color ''blue'' to create a
dimensionless background image.
<pre>background-image: image(wavy.svg, 'wavy.png' 150dpi, "wavy.gif" or blue);</pre>
<p>The 'background-image' property specifies that dimensionless images
must stretch to cover the entire background positioning area
[[CSS3BG]], so if none of the specified images can be displayed
the background will be painted blue. As with any image, this fallback
will be painted over the 'background-color' (if any).
</div>
<p>If the URL for the image ends in a file extension (a period followed by
letters) of four ascii letters ([a-zA-Z]) or less, then the UA <em>may</em>
skip trying to load images whose file extension matches an image format it
knows it does not support. For example, a UA that knows it supports JPEG and
GIF, but expects to encounter many PNG and SVG images may choose to skip over
images with filenames ending in '.png' or '.svg' without loading them to
check their MIME type. However it must not skip over images with filenames
ending in extensions it doesn't recognize.
</div>
<div>
<h2>Image Sprites</h2>
<p>The image sprites syntax is different from image slices noted above.
Image slice syntax allows you to specify the coordinates of a region
in the image and use that as a standalone image, but all the coordinates
must be specified inline. This is great for one-off cutouts, but becomes
unnecessarily verbose when the slices fit into a grid structure. The goal
of this section is to define a syntax that:
<ul>
<li>Makes it easy to specify an image slice and swap it out in later
subclass or :hover rules.
<li>Makes it easy to maintain a sprite image, so that adding or shifting
sections of the image don't require crawling through and modifying the
entire style sheet.
<li>Has straightforward handling of strict grids, but can also handle
more irregular sprite organization.
<li>(Any other use cases/requirements?)
</ul>
<div class="issue">
<p>As yet unwritten. Discussions/proposals include:</p>
<ul>
<li><a href="http://lists.w3.org/Archives/Public/www-style/2009May/0157.html">Jorrit's @sprite proposal</a>
<li><a href="http://www.css3.info/summary-of-the-two-current-css-constants-proposals/#comment-212898">Adrian's image-vars proposal</a>
<li><a href="http://lists.w3.org/Archives/Public/www-style/2009Jan/0185.html">Discussion from Jan 2008</a> and <a href="http://lists.w3.org/Archives/Public/www-style/2009Jan/0284.html">Jorrit's response</a>
</ul>
</div>
</div>
<div>
<h2>Gradients</h1>
<p>A gradient is a browser-generated image specified entirely in CSS, which consists of smooth fades between several colors. There are two basic kinds of gradients currently defined, linear and radial. These are specified by the <code>linear-gradient()</code> and <code>radial-gradient()</code> functions, and can be used any place an image can currently be used.</p>
<p>In many places this specification references a box, such as "the box's top-left corner" or "the box's right side". In all of these circumstances, the "box" refers to the 'CSS View Box' (see the "View Boxes" section of this spec for clarification). A gradient's 'Image View Box' has no intrinsic dimensions. This means that, for example, if you use a gradient in a background-image, the "box" will simply be the size of the background area. If you use a gradient in a list-style-image, the "box" will be a 1em square.</p>
<div class=example>
<p>As with the other <image> types defined in this specification, gradients can be used in any property that accepts images. For example:</p>
<ul>
<li><code>background: linear-gradient(white, gray);</code></li>
<li><code>list-style-image: radial-gradient(circle, #006, #00a 90%, #0000af 100%, white 100%)</code></li>
</ul>
</div>
<div>
<h3>Linear Gradients</h3>
<p>A linear gradient is created by specifying a gradient-line and then several colors placed along that line. The image is constructed by creating an infinite canvas and painting it with lines perdendicular to the gradient-line, with the color of the painted line being the color of the gradient-line where the two intersect.</p>
<h4 class=no-toc><code>linear-gradient()</code> syntax</h4>
<pre class=prod><code>linear-gradient([<bg-position> || <angle>,]? <color-stop>, <color-stop>[, <color-stop>]*);</code></pre>
<p>The first argument to the function specifies the <strong>gradient-line</strong>, which gives the gradient a direction and determines how color-stops are positioned. It may be omitted; if so, it defaults to "<code>top</code>".</p>
<p>The gradient's color stops are typically placed between the starting-point and ending-point on the gradient-line, but this is not required. The starting-point and ending-point are merely arbitrary distance markers - the starting-point defines where 0%, 0px, etc are located when specifying color-stops, and the ending-point defines where 100% is located. Color stops are allowed to have positions before 0% or after 100%.</p>
<p><code><bg-position></code> is taken from the Backgrounds and Borders Module, and has the same definition. <code><angle></code> is from the Values Module, and has the same definition.</p>
<p>If only a <code><bg-position></code> is specified, it specifies the starting-point of the gradient-line. The ending-point is obtained by rotating the starting-point 180 degrees around the center of the box.</p>
<p>If only a <code><angle></code> is specified, it specifies the direction of the gradient-line, and the starting-point and ending-point of the gradient-line are implied by the value of the <code><angle></code> as follows:
<ul>
<li>If the <code><angle></code> is greater than or equal to 0deg and less then 90deg, the starting-point of the gradient-line is the bottom-left corner of the gradient-box.</li>
<li>If the <code><angle></code> is greater than or equal to 90deg and less then 180deg, the starting-point of the gradient-line is the bottom-right corner of the gradient-box.</li>
<li>If the <code><angle></code> is greater than or equal to 180deg and less then 270deg, the starting-point of the gradient-line is the top-right corner of the gradient-box.</li>
<li>If the <code><angle></code> is greater than or equal to 270deg and less then 360deg, the starting-point of the gradient-line is the top-left corner of the gradient-box.</li>
</ul>
<p>The ending-point of the gradient-line is the point on the gradient-line where a line drawn perpendicular to the gradient-line would intersect the opposite corner from the starting-point.</p>
<p>If both a <code><bg-position></code> and <code><angle></code> are specified, the starting-point of the gradient-line is determined by the <code><bg-position></code>, the gradient-line extends at the <code><angle></code>, and the ending-point is determined in a way similar to the previous case - based on the <code><angle></code>, determine a "starting corner" and an opposing "ending corner", and set the ending-point of the gradient-line as the point on the gradient-line where a line drawn perpendicular to the gradient-line would intersect the "ending corner".</p>
<p class=note>Note that, in some cases, this may cause the gradient to "reverse direction". For example, if you specify "-10px -10px 135deg" as the first argument, it produces a display identical to if you had had specified "-10px -10px 315deg", because the "ending corner" is "behind" the starting-point of the gradient-line.</p>
<p>If both are omitted, it is equivalent to simply specifying "top" for the first argument. That is, it defines a vertical gradient starting at the top and ending at the bottom.</p>
<p>If both starting-point and ending-point are the same, then the gradient is just a solid color, defined by the last color-stop in the list. For example, "left top 90deg" will result in a solid-color gradient (since it has 90deg, the "ending corner" is the top-left, which is where it starts), as will "center" (to obtain the ending-point, you rotate the starting-point around the center - rotating the center around the center gives you the center).</p>
<div class=example>
This example illustrates visually how to calculate the gradient-line from the rules above. This shows the starting and ending-point of the gradient-line, along with the actual gradient, produced by an element with ''background: linear-gradient(45deg, white, black);''.
<p><img src='gradient-line-example.png' alt></p>
</div>
<h4><code>color-stop</code> Syntax</h4>
<p>The <dfn><code><color-stop></code></dfn> stands for:</p>
<pre class=prod><code><color> [ <percentage> | <length> ]?</code></pre>
<p>Color-stops are points placed along the line defined by the gradient-line at the beginning of the rule. Color-stops must be specified in order. Percentages refer to the length of the gradient-line, with 0% being at the starting point and 100% being at the ending point. Lengths are measured from the starting-point in the direction of the ending-point. With either measure, color-stops may be placed before the starting-point or after the ending-point; this is perfectly valid, as the starting-point and ending-point are just convenient references, and do not directly interact in the display of the gradient. At each color-stop, the line is the color of the color-stop. Before the first color-stop, the line is the color of the first color-stop. After the last color-stop, the line is the color of the last color-stop. Between two color-stops, the colors are interpolated as SVG gradients.</p>
<p>The following steps must be applied <em>in order</em> to process the list of color-stops. After applying these rules, all color-stops will have a definite position and they will be in ascending order:</p>
<ol>
<li>If the first color-stop does not have a position, its position defaults to 0%. If the last color-stop does not have a position, its position defaults to 100%.</li>
<li>If a color-stop has a position that is less than the specified position of any color-stop before it in the list, its position is changed to be equal to the largest specified position of any color-stop before it.</li>
<li>If any color-stop still does not have a position, then, for each run of adjacent color-stops without positions, set their positions so that they are evenly spaced between the preceding and following color-stops with positions.</li>
</ol>
<p>If multiple color-stops have the same position, they produce an infinitesimal transition from the one specified first in the rule to the one specified last. In effect, the color suddenly changes at that position rather than smoothly transitioning.</p>
<p class=note>It is recommended that authors not mix different types of units, such as px, em, or %, in a single rule, as this can cause a color-stop to unintentionally try to move before an earlier one. For example, the rule <code>background-image: linear-gradient(red, yellow 100px, blue 50%)</code> would work as expected as long as the background area is at least 200px tall. If it was 150px tall, however, the blue color-stop would be specifying a position of "75px", which precedes the yellow color-stop, and would be corrected to a position of 100px.</p>
<h4 class=no-toc>Linear Gradient Examples</h4>
<p>All of the following <code>linear-gradient()</code> examples are presumed to be backgrounds applied to a box that is 200px wide and 100px tall.</p>
<div class=example>
<p>Below are various ways of specifying a basic vertical gradient:</p>
<pre><code>linear-gradient(top, yellow, blue);
linear-gradient(bottom, blue, yellow);
linear-gradient(-90deg, yellow, blue);
linear-gradient(270deg, yellow, blue);
linear-gradient(top, yellow 0%, blue 100%);
linear-gradient(center top, yellow, blue);
linear-gradient(yellow, blue);</code></pre>
<p><img src="linear1.png" alt="" ></p>
</div>
<div class=example>
<p>This gradient goes from the upper-left to the lower-right corner.</p>
<pre><code>linear-gradient(top left, yellow, blue);
linear-gradient(0 0, yellow, blue);
linear-gradient(top 0px left 0px, yellow, blue);
linear-gradient(bottom right, blue, yellow);</code></pre>
<p><img src="linear2.png" alt="" ></p>
</div>
<div class=example>
<p>This demonstrates the use of an angle in the gradient. Compare this image with the previous example. In both gradients, the top-left of the box is pure yellow, and the bottom-right of the box is pure blue. The difference is in the angle that the gradient follows.</p>
<pre><code>linear-gradient(-45deg, yellow, blue);
linear-gradient(315deg, yellow, blue);</code></pre>
<p><img src="linear3.png" alt="" ></p>
</div>
<div class=example>
<p>This demonstrates a 3-color gradient, and how to specify the location of a stop explicitly:</p>
<pre><code>linear-gradient(top, yellow, blue 20%, #0f0);</code></pre>
<p><img src="linear4.png" alt="" ></p>
</div>
<div class=example>
<p>Here we use the full background-position syntax to specify the direction of the gradient. Notice that in this example a substantial portion of the image is pure yellow and pure blue, because the starting and ending points of the gradient-line are not on the box edge, but rather somewhere within the box.</p>
<pre><code>linear-gradient(20px 30px, yellow, blue);
linear-gradient(left 20px top 30px, yellow, blue);</code></pre>
<p><img src="linear5.png" alt="" ></p>
</div>
</div>
<div>
<h3>Radial Gradients</h3>
<p>A radial gradient is specified in a manner very similar to a linear gradient. You define a gradient-line by providing a starting-point and an angle and place color-stops along this line, but also specify a gradient-shape that determines where the gradient-line ends and the overall appearance of the gradient image. The image is constructed by creating an infinite canvas and painting it with concentric scaled copies of the ending-shape, with the color of the painted shape being the color of the gradient-line where the two intersect.</p>
<h4 class=no-toc><code>radial-gradient()</code> Syntax</h4>
<pre class=prod><code>radial-gradient([<bg-position> || <angle>,]? [<shape> || <size>,]? <color-stop>, <color-stop>[, <color-stop>]*)</code></pre>
<p>The first argument to the function specifies the <strong><code>gradient-line</code></strong>. <code><bg-position></code> is taken from the Backgrounds and Borders Module, and has the same definition. It specifies the starting-point of the gradient-line, and the center of the gradient-shape. If omitted, it defaults to <code>center</code>. <code><angle></code> is from the Values Module, and has the same definition. If omitted, it defaults to 0deg. The gradient-line extends from the starting-point at this angle.</p>
<p>The second argument to the function specifies the <strong><code>gradient-shape</code></strong>. <code><shape></code> is defined as <code>[ circle | ellipse ]</code>. <code>circle</code> indicates that the gradient-shape will be a circle with a constant radius. <code>ellipse</code> indicates that the gradient-shape will be an axis-aligned ellipse (that is, its major and minor radiuses will be horizontal and vertical, not necessarily in that order). If omitted, it defaults to <code>ellipse</code>.</p>
<p><code><size></code> is defined as <code>[ closest-side | closest-corner | farthest-side | farthest-corner | contain | cover ]</code>. If <code><shape></code> is <code>circle</code> and <code><size></code> is <code>closest-side</code>, the ending-shape is a circle sized so that it exactly meets the side of the box closest to its center. For example, if the box was 100px wide and 200px tall, and the starting-point of the gradient-line was <code>'10% 10%'</code>, then the closest side is the left side of the box (it is 10px from the starting-point, while the top is 20px from it, and the right and bottom sides are much further). The gradient-shape would be a circle with a radius of 10px. If <code><shape></code> is <code>ellipse</code> and <code><size></code> is <code>closest-side</code>, the gradient-shape is an ellipse sized so that it exactly meets the vertical and horizontal sides of the box closest to its center. Using the same box and starting-point as the previous example, the gradient-shape would be an ellipse with a 20px vertical radius and a 10px horizontal radius. (If necessary, such as if the starting-point is outside of the box, extend the sides of the box so that there is a line the ellipse can meet.)</p>
<p><code>farthest-side</code> is identical to <code>closest-side</code>, except that the gradient-shape is sized to meet the side of the box that is farthest from its center (or the farthest vertical and horizontal sides, in the case of <code>ellipse</code>). <code>closest-corner</code> and <code>farthest-corner</code> size the gradient-shape so that it exactly meets the closest or farthest corner of the box from its center, respectively. If <code><shape></code> is <code>ellipse</code>, the gradient-shape has the same ratio of width to height that it would if <code>closest-side</code> or <code>farthest-side</code> were specified, as appropriate. <code>contain</code> is a synonym for <code>closest-side</code>, and <code>cover</code> is a synonym for <code>farthest-corner</code>. If omitted, <code><size></code> defaults to <code>cover</code>.</p>
<p>In certain circumstances the given parameters may define a degenerate shape - a circle or ellipse with a radius of 0. In these instances the gradient image is just a solid color equal to the color of the last color-stop in the rule. The following combinations of values will trigger this: <code>closest-side</code> if the starting-point is on a box edge, <code>closest-corner</code> if the starting-point is on a box corner, and <code>ellipse</code> and <code>closest-corner</code> if the starting-point is on a box edge.</p>
<p>The ending-point of the gradient-line is determined by extending a line from the starting-point in the direction specified by the <code><angle></code> in the first argument. The ending-point is where this line intersects the gradient-shape.</p>
<p><code><color-stop></code> is defined identically to its treatment in <code>linear-gradient()</code>. As in linear gradients, 0% is at the starting-point of the gradient-line, and 100% is at the ending-point. Distances past 100% can be specified, and simply indicate a color-stop placed on the gradient-line a corresponding distance from the starting-point. Negative distances are allowed in a radial gradient and work the same as in linear gradients with respect to setting the color of the gradient-line, but colors before the starting-point of the gradient-line are not displayed. For example, <code>radial-gradient(red -50px, yellow 100px)</code> would produce an elliptical gradient which starts with a reddish-orange color in the center (the color 1/3 between red and yellow) and transitions to yellow at 100px wide.</p>
<h4 class=no-toc>Radial Gradient Examples</h4>
<p>All of the following examples are applied to a box that is 200px wide and 100px tall.</p>
<div class=example>
<p>These examples demonstrate the basic syntax for radial gradients:</p>
<pre><code>radial-gradient(yellow, green);
radial-gradient(center, ellipse cover, yellow 0%, green 100%);
radial-gradient(50% 50%, farthest-corner, yellow, green);</code></pre>
<p><img src="radial1.png" alt="" ></p>
<pre><code>radial-gradient(circle, yellow, green);</code></pre>
<p><img src="radial2.png" alt="" ></p>
<pre><code>radial-gradient(red, yellow, green);</code></pre>
<p><img src="radial3.png" alt="" ></p>
</div>
<div class=example>
<p>The next two images show a gradient originating from somewhere other than the center of the box:</p>
<pre><code>radial-gradient(bottom left, farthest-side, red, yellow 50px, green);</code></pre>
<p><img src="radial4.png" alt="" ></p>
<pre><code>radial-gradient(bottom left 90deg, farthest-side, red, yellow 50px, green);</code></pre>
<p><img src="radial5.png" alt="" ></p>
<p>Pay attention to the differences in these two images. In both of them the distance between the red color-stop and the yellow color-stop is 50px; the difference is the <em>direction</em> this distance is measured. By default the angle is 0deg, which means that distances are measured from the center going right. An angle of 90deg makes it measure from the center going up. Specifying an angle between 0deg and 90deg would produce a gradient somewhere between these two examples.</p>
</div>
<div class=example>
<p>Here we illustrate a 'contain' gradient.</p>
<pre><code>radial-gradient(20px 30px, contain, red, yellow, green)</code></pre>
<p><img src="radial6.png" alt="" ></p>
<pre><code>radial-gradient(20px 30px, circle contain, red, yellow, green)</code></pre>
<p><img src="radial7.png" alt="" ></p>
</div>
</div>
<!-- Removed for lack of a use-case; we'll just leave it as a vendor-prefix for now.
<div>
<h3>Repeating Gradients</h3>
<p>In addition to the <code>linear-gradient()</code> and <code>radial-gradient()</code> functions, this specification defines <code>repeating-linear-gradient()</code> and <code>repeating-radial-gradient()</code> functions. These two functions take the same values and are interpreted the same as their respective non-repeating siblings defined previously. However, the color-stops are repeated infinitely in both directions, with their positions shifted by multiples of the difference between the last color-stop's position and the first color-stop's position. For example, <code>repeating-linear-gradient(red 10px, blue 50px)</code> is equivalent to <code>linear-gradient(..., red -30px, blue 10px, red 10px, blue 50px, red 50px, blue 90px, ...)</code>. Note that the last color-stop and first color-stop will always coincide at the boundaries of each group, which may produce sharp transitions if the gradient does not start and end with the same color.</p>
<div class=example>
<p>Repeating gradient syntax is basically identical to that of non-repeating gradients:</p>
<pre><code>repeating-linear-gradient(red, blue 20px, red 40px)</code></pre>
<p><img src="repeating1.png" alt=""></p>
<pre><code>repeating-radial-gradient(red, blue 20px, red 40px)</code></pre>
<p><img src="repeating2.png" alt=""></p>
<pre><code>repeating-radial-gradient(20px 30px, circle contain, red, yellow, green 100%, yellow 150%, red 200%)</code></pre>
<p><img src="repeating3.png" alt=""></p>
</div>
<p>If the difference in the first and last color-stops is 0 (for example, in the rule <code>linear-gradient(red 10px, blue 10px)</code>), the gradient defines a solid-color image with the color of the last color-stop in the rule (in this case, then, it would simply define a blue image).</p>
</div>
-->
</div>
<div>
<h2>View Boxes, or Sizing Images and Objects in CSS</h2>
<p>Images used in CSS may come from a number of sources, from defined image formats (such as gif, jpeg, etc), dedicated markup formats (such as SVG), and CSS-specific formats (such as the linear-gradient() value type defined in this specification). As well, a document may conain many other types of objects, such as video, plugins, or nested documents. These images and objects (just "objects" hereafter) may offer many types of sizing information to CSS, or none at all. This section defines generically the size negotiation model between the image or replaced content object and the CSS layout algorithms.</p>
<p>In order to define this handling, we must define a few terms, to make it easier to refer to various concepts:</p>
<dl>
<dt><dfn>intrinsic dimensions</dfn></dt>
<dd>The intrinsic dimensions are defined are the object's preferred, natural size or aspect ratio, if any. There can be an <dfn>intrinsic height</dfn> and <dfn>intrinsic width</dfn>, defining a definite rectangle. (Most bitmap images fall into this category.) There can be an <dfn>intrinsic aspect ratio</dfn> defining the relation of the width to the height, but no definite size. (SVG images designed to scale may fall into this category.) There can be just an intrinsic height or width. Or there can be no intrinsic dimensions at all, implying that the object has no preferred size or aspect ratio. (Embedded documents are often assumed to have no intrinsic size, as are CSS gradients, defined in this specification.)
<p>If an object (such as an icon) has multiple sizes, then the largest size is used. If it has multiple aspect ratios of that size (or of no size), then the aspect ratio closest to the aspect ratio of the default image sizing area is use <span class="issue">This is pretty arbitrary</span>.</p></dd>
<dt><dfn>specified size</dfn></dt>
<dd>The specified size of an object is given by CSS, such as through the `object-fit` or `background-size` properties. The specified size can be a definite width and height, a set of constraints, or a combination thereof.</dd>
<dt><dfn>CSS View Box</dfn></dt>
<dd>The CSS View Box is the result of transforming the intrinsic dimensions into a concrete size, based on the specified size and the default image sizing area. A CSS View Box always has a definite height and width.</dd>
<dt><dfn>default image sizing area</dfn></dt>
<dd>The default image sizing area is a rectangle with a definite height and width used to determine the size of the CSS View Box when both the intrinsic dimensions and specified size are missing dimensions.</dd>
</dl>
<p>Images and objects in CSS are sized as follows:</p>
<ol>
<li>When an image or object is specified in a document, such as through url() value in a background-image property or a @src attribute on an <img> element, CSS queries the object for its intrinsic size.</li>
<li>Using the intrinsic dimensions and the specified size, CSS then computes a CSS View Box that defines the size of the region the object will render in, as follows:
<ol>
<li>If the specified size is just a definite width and height, the CSS View Box must be that width and height.</li>
<li>If the specified size is just a definite width or just a definite height, then the CSS View Box must have the same width or height, as appropriate. The other dimension is calculated as follows:
<ol>
<li>If the object has an intrinsic aspect ratio, the CSS View Box must have the same aspect ratio..</li>
<li>Otherwise, if the object has an an intrinsic height or intrinsic width (whichever is missing from the specified size), then the CSS View Box must have that height or width.</li>
<li>Otherwise, the CSS View Box must have the same width or height (whichever is missing from the specified size) as the default image sizing area.</li>
</ol>
</li>
<li>If the specified size is neither a definite width nor height, and has no additional contraints, the dimensions of the CSS View Box must be computed as follows:
<ol>
<li>If the object has an intrinsic width and an intrinsic height, the CSS View Box must have that same height and width.</li>
<li>If the object has only an intrinsic width or intrinsic height, and no intrinsic aspect ratio, the CSS View Box must have that height or width, and the width or height (whichever is missing from the intrinsic dimensions) of the default image sizing area.</li>
<li>If the object has only an intrinsic aspect ratio, the CSS View Box must have that aspect ratio, and additionally be as large as possible without either its height or width exceeding the height or width of the default image sizing area.</li>
<li>Otherwise, the CSS View Box must be the size of the default image sizing area.</li>
</ol>
</li>
<li>If the specified size has additional constraints, the CSS View Box must be sized to satisfy those constraints. (For example, object-fit:contain specifies slightly more complex handling for sizing replaced elements, and background-repeat:round can adjust the size specified in background-size so that the image fits an even number of times into the background positioning area.)</li>
</ol>
</li>
</ol>
<p>After determining the size of the CSS View Box, CSS positions it within the appropriate area according to any relevant properties, such as object-position or background-position, and asks the object to render itself using the dimensions of the CSS View Box. CSS does not define how objects when the dimensions of the CSS View Box are different than the object's intrinsic dimensions. The object may adjust itself to match the dimensions of the CSS View Box in some way, or even render itself larger or smaller than the CSS View Box to satisfy sizing constraints of its own.</p>
</div>
<div>
<h2>Resolution Units: the <resolution> value type</h2>
<p>This specification defines the following units as part of the
<dfn><resolution></dfn> value type:
<dl>
<dt>dpi <dd>dots per inch
<dt>dpcm <dd>dots per centimeter
<dt>dppx <dd>dots per ''px'' unit
</dl>
<p class="note">The default resolution of raster images in CSS is ''1dppx''.</p>
</div>
<h2 class="no-num" id="acknowledgments">Acknowledgments</h2>
<h2 class="no-num" id="references">References</h2>
<h3 class="no-num" id="normative-references">Normative references</h3>
<!--begin-normative-->
<p>[Here will be inserted the file "normative.inc"]</p>
<!--end-normative-->
<h3 class="no-num" id="informative-references">Informative references</h3>
<!--begin-informative-->
<p>[Here will be inserted the file "informative.inc"]</p>
<!--end-informative-->
</body>
</html>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-declaration:"~/SGML/HTML4.decl"
sgml-default-doctype-name:"html"
sgml-minimize-attributes:t
sgml-nofill-elements:("pre" "style" "br")
sgml-live-element-indicator:t
sgml-omittag:nil
sgml-shorttag:nil
sgml-namecase-general:t
sgml-general-insert-case:lower
sgml-always-quote-attributes:t
sgml-indent-step:nil
sgml-indent-data:t
sgml-parent-document:nil
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
-->