-
Notifications
You must be signed in to change notification settings - Fork 790
Expand file tree
/
Copy pathOverview.html
More file actions
2363 lines (1830 loc) · 98.2 KB
/
Overview.html
File metadata and controls
2363 lines (1830 loc) · 98.2 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
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang=en>
<head><meta content="text/html; charset=utf-8" http-equiv=Content-Type>
<title>CSS Image Values and Replaced Content Module Level 3</title>
<!--<link rel="stylesheet" type="text/css" href="../default.css">-->
<link href="http://dev.w3.org/csswg/css-module/default.css" rel=stylesheet
type="text/css">
<link href="http://www.w3.org/StyleSheets/TR/W3C-ED" rel=stylesheet
type="text/css">
<body>
<div class=head> <!--begin-logo-->
<p><a href="http://www.w3.org/"><img alt=W3C height=48
src="http://www.w3.org/Icons/w3c_home" width=72></a> <!--end-logo-->
<h1>CSS Image Values and Replaced Content Module Level 3</h1>
<h2 class="no-num no-toc" id=longstatus-date>Editor's Draft 4 November
2011</h2>
<dl>
<dt>This Version:</dt>
<!--<dd><a href="http://www.w3.org/TR/2011/ED-css3-images-20111104/">http://www.w3.org/TR/2011/WD-css3-images-20111104/</a>-->
<dd><a
href="http://dev.w3.org/csswg/css3-images/">http://dev.w3.org/csswg/css3-images/</a>
<dt>Latest Version:
<dd><a
href="http://www.w3.org/TR/css3-images/">http://www.w3.org/TR/css3-images/</a>
<dt>Editor's Draft:
<dd><a
href="http://dev.w3.org/csswg/css3-images/">http://dev.w3.org/csswg/css3-images/</a>
<dt>Previous Version:
<dd><a
href="http://www.w3.org/TR/2011/WD-css3-images-20110908/">http://www.w3.org/TR/2011/WD-css3-images-20110908/</a>
<dd><a
href="http://www.w3.org/TR/2011/WD-css3-images-20110712/">http://www.w3.org/TR/2011/WD-css3-images-20110712/</a>
<dd><a
href="http://www.w3.org/TR/2011/WD-css3-images-20110217/">http://www.w3.org/TR/2011/WD-css3-images-20110217/</a>
<dd><a
href="http://www.w3.org/TR/2009/WD-css3-images-20090723/">http://www.w3.org/TR/2009/WD-css3-images-20090723/</a>
<dt>Editors:
<dd><a href="http://fantasai.inkedblade.net/contact">Elika J. Etemad</a>
(Mozilla Corporation)
<dd><a href="http://www.xanthir.com/contact/">Tab Atkins Jr.</a> (Google)
</dl>
<!--begin-copyright-->
<p class=copyright><a
href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright"
rel=license>Copyright</a> © 2011 <a
href="http://www.w3.org/"><acronym
title="World Wide Web Consortium">W3C</acronym></a><sup>®</sup> (<a
href="http://www.csail.mit.edu/"><acronym
title="Massachusetts Institute of Technology">MIT</acronym></a>, <a
href="http://www.ercim.eu/"><acronym
title="European Research Consortium for Informatics and Mathematics">ERCIM</acronym></a>,
<a href="http://www.keio.ac.jp/">Keio</a>), All Rights Reserved. W3C <a
href="http://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>,
<a
href="http://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a>
and <a
href="http://www.w3.org/Consortium/Legal/copyright-documents">document
use</a> rules apply.</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 <a href="#ltimage"><i><image></i></a> values
in CSS. <a href="#ltimage"><i><image></i></a> values can be a single
URI to an image, a list of URIs denoting a series of fallbacks, a
reference to an element in the document, 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>
<!--begin-status-->
<p>This is a public copy of the editors' draft. It is provided for
discussion only and may change at any moment. Its publication here does
not imply endorsement of its contents by W3C. Don't cite this document
other than as work in progress.
<p>The (<a
href="http://lists.w3.org/Archives/Public/www-style/">archived</a>) public
mailing list <a
href="mailto:www-style@w3.org?Subject=%5Bcss3-images%5D%20PUT%20SUBJECT%20HERE">
www-style@w3.org</a> (see <a
href="http://www.w3.org/Mail/Request">instructions</a>) is preferred for
discussion of this specification. When sending e-mail, please put the text
“css3-images” in the subject, preferably like this:
“[<!---->css3-images<!---->] <em>…summary of
comment…</em>”
<p>This document was produced by the <a href="/Style/CSS/members">CSS
Working Group</a> (part of the <a href="/Style/">Style Activity</a>).
<p>This document was produced by a group operating under the <a
href="/Consortium/Patent-Policy-20040205/">5 February 2004 W3C Patent
Policy</a>. W3C maintains a <a href="/2004/01/pp-impl/32061/status"
rel=disclosure>public list of any patent disclosures</a> made in
connection with the deliverables of the group; that page also includes
instructions for disclosing a patent. An individual who has actual
knowledge of a patent which the individual believes contains <a
href="/Consortium/Patent-Policy-20040205/#def-essential">Essential
Claim(s)</a> must disclose the information in accordance with <a
href="/Consortium/Patent-Policy-20040205/#sec-Disclosure">section 6 of the
W3C Patent Policy</a>.</p>
<!--end-status-->
<p>The following features are at risk:
<ol>
<li>The <a href="#image-notation">image() function</a>
<li>The <a href="#element-reference">element() function</a>
<li>The "none" and "scale-down" values for ‘<a
href="#object-fit0"><code class=property>object-fit</code></a>’
<li>The ‘<a href="#image-orientation0"><code
class=property>image-orientation</code></a>’ property
<li>The "snap" keyword for ‘<a href="#image-resolution0"><code
class=property>image-resolution</code></a>’
</ol>
<!-- ====================================================================== -->
<h2 class="no-num no-toc" id=contents> Table of Contents</h2>
<!--begin-toc-->
<ul class=toc>
<li><a href="#intro"><span class=secno>1. </span> Introduction</a>
<li><a href="#conformance"><span class=secno>2. </span> Conformance</a>
<li><a href="#resolution-units"><span class=secno>3. </span> Resolution
Units: the <resolution> type</a>
<li><a href="#image"><span class=secno>4. </span> Image Values: the
<image> type</a>
<ul class=toc>
<li><a href="#url"><span class=secno>4.1. </span> Image References and
Image Slices: the ‘<code class=css>url()</code>’
function</a>
<li><a href="#image-notation"><span class=secno>4.2. </span> Image
Fallbacks and Annotations: the ‘<code
class=css>image()</code>’ notation</a>
<li><a href="#element-reference"><span class=secno>4.3. </span> Using
Elements as Images: the ‘<code class=css>element()</code>’
function</a>
</ul>
<li><a href="#gradients"><span class=secno>5. </span> Gradients</a>
<ul class=toc>
<li><a href="#linear-gradients"><span class=secno>5.1. </span> Linear
Gradients</a>
<li><a href="#radial-gradients"><span class=secno>5.2. </span> Radial
Gradients</a>
<li><a href="#repeating-gradients"><span class=secno>5.3. </span>
Repeating Gradients</a>
<li><a href="#color-stop-syntax"><span class=secno>5.4. </span> Gradient
Color-Stops</a>
</ul>
<li><a href="#sizing"><span class=secno>6. </span> Sizing Images and
Objects in CSS</a>
<ul class=toc>
<li><a href="#sizing-terms"><span class=secno>6.1. </span> Object-Sizing
Terminology</a>
<li><a href="#object-negotiation"><span class=secno>6.2. </span>
CSS⇋Object Negotiation</a>
<li><a href="#default-sizing"><span class=secno>6.3. </span> Concrete
Object Size Resolution</a>
<li><a href="#object-fit"><span class=secno>6.4. </span> Sizing Objects:
the ‘<code class=property>object-fit</code>’ property</a>
<li><a href="#object-position"><span class=secno>6.5. </span>
Positioning Objects: the ‘<code
class=property>object-position</code>’ property</a>
</ul>
<li><a href="#image-processing"><span class=secno>7. </span> Image
Processing</a>
<ul class=toc>
<li><a href="#image-resolution"><span class=secno>7.1. </span>
Overriding Image Resolutions: the ‘<code
class=property>image-resolution</code>’ property</a>
<li><a href="#image-orientation"><span class=secno>7.2. </span>
Orienting an Image on the Page: the ‘<code
class=property>image-orientation</code>’ property</a>
</ul>
<li class=no-num><a href="#acknowledgments">Acknowledgments</a>
<li class=no-num><a href="#references">References</a>
<ul class=toc>
<li class=no-num><a href="#normative-references">Normative
references</a>
<li class=no-num><a href="#informative-references">Informative
references</a>
</ul>
<li class=no-num><a href="#property-index">Property index</a>
<li class=no-num><a href="#index">Index</a>
</ul>
<!--end-toc-->
<!-- ====================================================================== -->
<h2 id=intro><span class=secno>1. </span> Introduction</h2>
<p><em>This section is non-normative.</em>
<p>In CSS Levels 1 and 2, image values, such as those used in the
‘<code class=property>background-image</code>’ 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 reference to an element in the document, and as a
gradient.</p>
<!-- ====================================================================== -->
<h2 id=conformance><span class=secno>2. </span> Conformance</h2>
<p>A document or implementation cannot conform to CSS Image Values &
Replaced Content Level 3 alone, but can claim conformance to CSS Image
Values & Replaced Content Level 3 if it satisfies the conformance
requirements in this specification when implementing CSS or another host
language that normatively references this specification.
<p>Conformance to CSS Image Values & Replaced Content Level 3 is defined
for three classes:
<dl>
<dt><dfn id=minimal>minimal</dfn>
<dd>A device that does not implement CSS Transitions, CSS Animations, nor
CSSOM may ignore the chapters on Serializing and Interpolating values for
the purpose of claiming conformance.
<dt><dfn id=transition-capable>transition-capable</dfn>
<dd>A device that implements CSS Transitions or CSS Animations must
conform to the <a href="#minimal"><i>minimal</i></a> class, and
additionally must implement the chapter on Interpolation.
<dt><dfn id=cssom-capable>CSSOM-capable</dfn>
<dd>A device that implements CSSOM must conform to the <a
href="#minimal"><i>minimal</i></a> class, and additionally must implement
the chapter on Serialization.
</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. <a
href="#RFC2119" rel=biblioentry>[RFC2119]<!--{{!RFC2119}}--></a>
<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>
<!-- ====================================================================== -->
<h2 id=resolution-units><span class=secno>3. </span> Resolution Units: the
<resolution> type</h2>
<p>This specification defines the following units as part of the <dfn
id=ltresolution><resolution></dfn> value type:
<dl>
<dt><dfn id=dpi>dpi</dfn>
<dd>dots per inch
<dt><dfn id=dpcm>dpcm</dfn>
<dd>dots per centimeter
<dt><dfn id=dppx>dppx</dfn>
<dd>dots per ‘<code class=css>px</code>’ unit
</dl>
<p>The <resolution> unit represents the size of a single "dot" of an
image. For raster images, a dot is an image pixel. A <resolution>
defines how many of these dots fit in a CSS ‘<code
class=property>in</code>’, ‘<code
class=property>cm</code>’, or ‘<code
class=property>px</code>’ so that images can be sized accordingly.
The default resolution of raster images in CSS is ‘<code
class=css>1dppx</code>’, which is equivalent to ‘<code
class=css>96dpi</code>’. The concept of "resolution" does not apply
to vector image formats like SVG; generally, this means that any attempt
to change the resolution of a vector image is simply meaningless.
Individual uses of the <resolution> value define precisely what effects
they have on raster and vector images.
<div class=example>
<p>Printers tend to have substantially higher resolution than computer
monitors; due to this, an image that looks fine on the screen may look
pixellated when printed out. A <resolution> may be used in the
‘<a href="#image-resolution0"><code
class=property>image-resolution</code></a>’ property to embed a
high-resolution image into the document that maintains an appropriate
size, ensuring attractive display both on screen and on paper:</p>
<pre class=css><code>
img.high-res {
image-resolution: 300dpi;
}</code></pre>
<p>With this set, an image meant to be 5 inches wide that was saved at
300dpi will actually display as 5 inches wide; without this set, the
image would display as approximately 15.6 inches wide since the image is
15000 image pixels across, and by default there are 96 image pixels per
inch.</p>
</div>
<!-- ====================================================================== -->
<h2 id=image><span class=secno>4. </span> Image Values: the <image> type</h2>
<p>The <image> value type denotes a 2D image. It is defined as
<pre class=prod><dfn
id=ltimage><image></dfn> = <url> | <image-list> | <element-reference> | <image-combination> | <gradient></pre>
<p>Image values can be used in many CSS properties, including the
‘<code class=property>background-image</code>’, ‘<code
class=property>list-style-image</code>’, ‘<code
class=property>cursor</code>’ properties <a href="#CSS21"
rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a>.
<!-- ====================================================================== -->
<h3 id=url><span class=secno>4.1. </span> Image References and Image
Slices: the ‘<code class=css>url()</code>’ function</h3>
<p>The simplest way to indicate an image is to reference an image file by
URL. This is done with the <a
href="http://www.w3.org/TR/CSS21/syndata.html#uri">‘<code
class=css>url()</code>’ notation</a>, defined in <a href="#CSS21"
rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a>.
<div class=example>
<p>In the example below, a background image is specified with ‘<code
class=css>url()</code>’ 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 <a
href="http://www.w3.org/TR/media-frags/#naming-space">media fragment
identifiers</a>. <a href="#MEDIA-FRAGS"
rel=biblioentry>[MEDIA-FRAGS]<!--{{!MEDIA-FRAGS}}--></a>
<div class=example>
<p>For example, given the following image* and CSS:</p>
<a href=sprites.svg> <img alt="[9 circles, with 0 to 8 eighths filled in]"
height=20 src=sprites.svg width=180> </a>
<pre>background-image: url('sprites.svg#xywh=40,0,20,20')</pre>
<p>...the background of the element will be the portion of the image that
starts at (40px,0px) and is 20px wide and tall, which is just the circle
with a quarter filled in.</p>
<p><small>* SVG-in-<img> support required. Click the picture to view
the SVG directly.</small></p>
</div>
<p class=note>Note that a legacy UA that doesn't understand the media
fragments notation will ignore the fragment and simply display the
entirety of an image specified with ‘<code
class=css>url</code>’. However, since URLs with media fragment
identifiers can also be used in the ‘<code
class=css>image()</code>’ notation defined below, authors can take
advantage of CSS's forward-compatible parsing rules to provide a fallback
when using an image fragment URL:
<div class=example>
<p>In the example below, the ‘<code class=css>image()</code>’
notation is used together with the media fragment syntax, so that UAs
that don't support media fragments fail to parse the second declaration
and use the first.</p>
<pre>
<!-- -->background-image: url('swirl.png'); /* old UAs */
<!-- -->background-image: image('sprites.png#xywh=10,30,60,20'); /* new UAs */</pre>
</div>
<!-- ====================================================================== -->
<h3 id=image-notation><span class=secno>4.2. </span> Image Fallbacks and
Annotations: the ‘<code class=css>image()</code>’ notation</h3>
<p>The ‘<code class=css>image()</code>’ function allows an
author to specify an image with fallback images to be used if the original
image can't be decoded or is a type that the browser doesn't recognize.
Additionally, the author can specify a color as an ultimate fallback to be
used when none of the images can be.
<p>Along with each URL, the author may specify a directionality, similar to
adding a <code>dir</code> attribute to an element in HTML. The image
represented by the function takes on the directionality of the used URL.
If a directional image is used on or in an element with opposite
directionality, the image must be flipped in the inline direction (as if
it was transformed by, e.g., <code>scaleX(-1)</code>, if the inline
direction is the X axis).
<p>So that authors can take advantage of CSS's forwards-compatible parsing
rules to provide a fallback for image slices, implementations that support
the ‘<code class=css>image()</code>’ notation <em>must</em>
support the <code>xywh=#,#,#,#</code> form of media fragment identifiers
for images. <a href="#MEDIA-FRAGS"
rel=biblioentry>[MEDIA-FRAGS]<!--{{!MEDIA-FRAGS}}--></a>
<p>The ‘<code class=css>image()</code>’ notation is defined as:
<pre class=prod><dfn id=ltimage-list><image-list></dfn> =
image( [ <image-decl> , ]* [ <image-decl> | <color> ] )
<image-decl> = <string> [ ltr | rtl ]?</pre>
<p>Each <code><string></code> must represent a <a
href="http://dev.w3.org/csswg/css3-values/#urls">URL</a>.
<p>Multiple arguments can be given separated by commas, in which case the
function represents the first <string> representing an image that the
browser can successfully load and display. The final argument can specify
a <color> to serve as an ultimate fallback; this can be used, e.g. for
‘<code class=property>background-image</code>’, to ensure
adequate contrast if none of the preceding <image-decl>s can be used.
If the final argument is a <color>, it represents a solid-color image
of the given color with no <a href="#intrinsic-dimensions"><i>intrinsic
dimensions</i></a>.
<div class=example>
<p>The rule below would tell the UA to load ‘<code
class=css>wavy.svg</code>’ if it can; failing that to load
‘<code class=css>wavy.png</code>’; failing that to display
‘<code class=css>wavy.gif</code>’; and finally, if none of
the images can be loaded and displayed, to use the color ‘<code
class=css>rgba(0,0,255,0.5)</code>’ to create a dimensionless
background image. For example, the browser might not understand how to
render SVG images, the PNG may be malformed, and the GIF might not exist
on the server and return an HTML 404 error page instead of an image.</p>
<pre>background-image: image("wavy.svg", 'wavy.png' , "wavy.gif", rgba(0,0,255,0.5));</pre>
<p>The ‘<code class=property>background-size</code>’ property
specifies that dimensionless images by default stretch to cover the
entire background positioning area <a href="#CSS3BG"
rel=biblioentry>[CSS3BG]<!--{{CSS3BG}}--></a>, so if none of the
specified images can be displayed the background will be painted
semi-transparent blue. As with any image, this fallback will be painted
over the ‘<code class=property>background-color</code>’ (if
any).</p>
</div>
<div class=example>
<p>At times, one may need a solid-color image for a property or function
that does not accept the <color> type directly. The ‘<code
class=css>image()</code>’ function can be used for this: by
specifying <em>only</em> a color without any URLs, the function
immediately falls back to representing a solid-color image of the chosen
color.
<pre>background-image: image(rgba(0,0,255,.5)), url("bg-image.png");</pre>
<p>In the above, the background is the image "bg-image.png", overlaid with
partially-transparent blue.
</div>
<!-- ====================================================================== -->
<h3 id=element-reference><span class=secno>4.3. </span> Using Elements as
Images: the ‘<code class=css>element()</code>’ function</h3>
<p>The ‘<code class=css>element()</code>’ function allows an
author to use an element in the document as an image. As the referenced
element changes appearance, the image changes as well. This can be used,
for example, to create live previews of the next/previous slide in a
slideshow, or to reference a canvas element for a fancy generated gradient
or even an animated background. The syntax for ‘<code
class=css>element()</code>’ is:
<pre class=prod><dfn
id=ltelement-reference><element-reference></dfn> = element( [<id-selector> | <identifier> ] )</pre>
<p>where <id-selector> is an ID selector <a href="#SELECT"
rel=biblioentry>[SELECT]<!--{{!SELECT}}--></a>, and <identifier> is an
identifer <a href="#CSS3VAL"
rel=biblioentry>[CSS3VAL]<!--{{!CSS3VAL}}--></a>.
<p>If the argument to the ‘<code class=css>element()</code>’
function is an ID selector, the function references the element matched by
the selector. If it's an identifier, the function references the element
whose <dfn id=css-element-reference-identifier>CSS element reference
identifier</dfn> is the given identifier. (CSS does not define how an
element acquires a <a href="#css-element-reference-identifier"><i>CSS
element reference identifier</i></a>; that is determined by the host
language.)
<p>The image represented by the ‘<code
class=css>element()</code>’ function can vary based on a number of
factors. The function must represent the image described by the first set
of conditions, following, that are true:
<dl>
<dt>The function doesn't reference an element
<dd>The function represents a solid-color transparent-black image with no
intrinsic dimensions.
<dt>The function references an element that is not rendered, but which <a
href="#paint-source"><i title=paint-source>provides a paint
source</i></a>
<dd>The function represents an image with the dimensions and appearance of
the <a href="#paint-source"><i title=paint-source>paint source</i></a>.
The host language defines the dimensions and appearance of paint sources.
<dt>The function references an element that is not rendered
<dt>The function references an element that is a descendant of a replaced
element
<dd>The function represents a solid-color transparent-black image with no
intrinsic dimensions.
<dt>Otherwise
<dd>
<p>The function represents an image with width and height equal to the
bounding box of the referenced element. The image must be constructed by
rendering the referenced element and its descendants at the same size
that the element would be in its document, over an infinite
transparent-black canvas, positioned so that the edges of the referenced
element's bounding box is flush with the edges of the image. <span
class=note>Note: Because images clip anything outside their bounds by
default, this means that decorations that extend outside the bounding
box, like box-shadows or some border-images, may be clipped.</span></p>
<p>If the referenced element has a transform applied to it or an
ancestor, the transform must be ignored when rendering the element as an
image. If the referenced element is broken across pages, the element
must be displayed as if the page content areas were joined flush in the
pagination direction (elements broken across lines or columns just
render with their bounding box, as normal, which may have unintended
visual effects).</p>
</dl>
<p>Implementations may either re-use existing bitmap data generated for the
referenced element or regenerate the display of the element to maximize
quality at the image's size (for example, if the implementation detects
that the referenced element is an SVG fragment); in the latter case, the
layout of the referenced element in the image must not be changed by the
regeneration process. That is, the image must look identical to the
referenced element, modulo rasterization quality.
<div class=example>
<p class=issue>TODO: Create examples of all of the above cases.</p>
</div>
<p>Host languages may define that some elements provide a <dfn
id=paint-source title=paint-source>paint source</dfn>. Paint sources have
an intrinsic width, height, and appearance, separate from the process of
rendering, and so may be used as images even when they're not being
rendered. Examples of elements that provide paint sources are the
<linearGradient>, <radialGradient>, and <pattern> elements in
SVG, or the <img>, <video>, and <canvas> elements in HTML.</p>
<!-- ====================================================================== -->
<h4 class="no-num no-toc" id=element-cycles> Detecting and Resolving
Circular Relationships Introduced by ‘<code
class=css>element()</code>’</h4>
<p>The ‘<code class=css>element()</code>’ function can produce
nonsensical circular relationships, such as an element using itself as its
own background. These relationships can be easily and reliably detected
and resolved, however, by keeping track of a dependency graph and using
common cycle-detection algorithms.
<p>Populate the dependency graph initially by having every element depend
on each of its children. Then, whenever a property on an element A uses
the ‘<code class=css>element()</code>’ function to refer to an
element B, add an edge to the graph by having A depend on B. If a
dependency cycle is detected, any ‘<code
class=css>element()</code>’ functions that produced a dependency in
the cycle must represent a fully transparent image with no intrinsic
dimensions.
<p class=issue>Someone else needs to review this and make sure that I'm not
missing any cycles.
<h2 id=gradients><span class=secno>5. </span> Gradients</h2>
<p>A gradient is an image that smoothly fades from one color to another.
These are commonly used for subtle shading in background images, buttons,
and many other things. The two functions described in this section allow
an author to specify such an image in a terse syntax, so that the UA can
generate the image automatically when rendering the page. The syntax of a
<a href="#ltgradient"><i><gradient></i></a> is:
<pre class=prod><dfn
id=ltgradient><gradient></dfn> = [ <linear-gradient> | <radial-gradient> | <repeating-linear-gradient> | <repeating-radial-gradient> ]</pre>
<p>where <a href="#ltlinear-gradient"><i><linear-gradient></i></a>, <a
href="#ltradial-gradient"><i><radial-gradient></i></a>, <a
href="#ltrepeating-linear-gradient"><i><repeating-linear-gradient></i></a>,
and <a
href="#ltrepeating-radial-gradient"><i><repeating-radial-gradient></i></a>
are defined in their applicable sections below.
<p>Gradients are a type of image, and can be used anywhere an image can,
such as in the ‘<code class=property>background-image</code>’
or ‘<code class=property>list-style-image</code>’ properties.
<div class=example>
<p>As with the other <a href="#ltimage"><i><image></i></a> 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><code>list-style-image: radial-gradient(circle, #006, #00a 90%,
#0000af 100%, white 100%)</code>
</ul>
</div>
<p>A gradient is drawn into a box with the dimensions of the <a
href="#concrete-object-size"><i>concrete object size</i></a>. Elsewhere in
this section this rectangle is simply called the "box".
<p>A gradient has no <a href="#intrinsic-dimensions"><i>intrinsic
dimensions</i></a>. This means that, for example, if you use a gradient in
the ‘<code class=property>background-image</code>’ property
(with ‘<code class=property>background-size</code>’ at the
default value and ‘<code
class=property>background-repeat</code>’ not equal to ‘<code
class=property>round</code>’), the box will simply be the size of
the background sizing area. Similarly, for a gradient used as a
list-style-image, the box would be a 1em square.
<!-- ====================================================================== -->
<h3 id=linear-gradients><span class=secno>5.1. </span> 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 perpendicular to
the gradient-line, with the color of the painted line being the color of
the gradient-line where the two intersect. This produces a smooth fade
from each color to the next, progressing in the specified direction.</p>
<!-- ====================================================================== -->
<h4 class=no-toc id=linear-gradient-syntax><span class=secno>5.1.1. </span>
linear-gradient() syntax</h4>
<pre class=prod><code><dfn
id=ltlinear-gradient><linear-gradient></dfn> = linear-gradient(
[ [ <angle> | [ to <side-or-corner> ] ] ,]?
<color-stop>[, <color-stop>]+
)
<dfn
id=side-or-corner><side-or-corner></dfn> = [left | right] || [top | bottom]</code></pre>
<p>The first argument to the function specifies the <dfn
id=gradient-line>gradient-line</dfn>, which gives the gradient a direction
and determines how color-stops are positioned. It may be omitted; if so,
it defaults to "to bottom".
<p>The <a href="#gradient-line"><i>gradient-line</i></a> may be specified
in two different ways. The first is by specifying the angle the <a
href="#gradient-line"><i>gradient-line</i></a> should assume; for the
purposes of this argument, 0deg points upwards, 90deg points toward the
right, and positive angles go clockwise. The starting-point and
ending-point of the <a href="#gradient-line"><i>gradient-line</i></a> are
determined by extending a line in both directions from the center of the
box at the angle
8D6C
specified. In the direction of the angle, the
ending-point is the point on the <a
href="#gradient-line"><i>gradient-line</i></a> where a line drawn
perpendicular to the <a href="#gradient-line"><i>gradient-line</i></a>
would intersect the corner of the box in that direction. The
starting-point is determined identically, except in the opposite direction
of the angle.
<p>Alternately, the direction may be specified with keywords that denote
the direction. If the argument is "to top", "to right", "to bottom", or
"to left", the gradient must be rendered identically to "0deg", "90deg",
"180deg", or "270deg", respectively. If the argument specifies a corner to
angle towards, the gradient must be rendered identically to an angle-based
gradient with an angle chosen such that the endpoint of the gradient is in
the same quadrant as the indicated corner, and a line drawn perpendicular
to the gradient-line through the center of the box intersects the two
neighboring corners.
<p class=note>It is expected that the next level of this module will
provide the ability to define the gradient's direction relative to the
current text direction and writing-mode.
<p>
<div class=example>
<div style="overflow: hidden"> <img
alt="[An image showing a box with a background shading gradually from white in the bottom-left corner to black in the top-right corner. There is a line, illustrating the gradient-line, angled at 45 degrees and passing through the center of the box. The starting-point and ending-point of the gradient-line are indicated by the intersection of the gradient-line with two additional lines that pass through the bottom-left and top-right corners of the box.]"
src=gradient-diagram.png style="float: right; margin-left: 1em;">
<p>This example illustrates visually how to calculate the <a
href="#gradient-line"><i>gradient-line</i></a> from the rules above.
This shows the starting and ending-point of the <a
href="#gradient-line"><i>gradient-line</i></a>, along with the actual
gradient, produced by an element with ‘<code class=css>background:
linear-gradient(45deg, white, black);</code>’.</p>
<p>Notice how, though the starting-point and ending-point are outside of
the box, they're positioned precisely right so that the gradient is pure
white <em>exactly</em> at the corner, and pure black <em>exactly</em> at
the opposite corner. That's intentional, and will always be true for
linear gradients.</p>
</div>
</div>
<p>The gradient's color stops are typically placed between the
starting-point and ending-point on the <a
href="#gradient-line"><i>gradient-line</i></a>, but this isn't required -
the <a href="#gradient-line"><i>gradient-line</i></a> extends infinitely
in both directions. The starting-point and ending-point are merely
arbitrary location 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>
<!-- ====================================================================== -->
<h4 class=no-toc id=linear-gradient-examples><span class=secno>5.1.2.
</span> Linear Gradient Examples</h4>
<p>All of the following ‘<code
class=css>linear-gradient()</code>’ examples are presumed to be
backgrounds applied to a box that is 200px wide and 100px tall.
<div class=example>
<p>Below are various ways of specifying a basic vertical gradient:</p>
<pre><code>linear-gradient(yellow, blue);
linear-gradient(to bottom, yellow, blue);
linear-gradient(180deg, yellow, blue);
linear-gradient(to top, blue, yellow);
linear-gradient(to bottom, yellow 0%, blue 100%);</code></pre>
<p><img alt="" src=linear1.png></p>
</div>
<div class=example>
<p>This demonstrates the use of an angle in the gradient. Note that,
though the angle is not exactly the same as the angle between the
corners, the <a href="#gradient-line"><i>gradient-line</i></a> is still
sized so as to make the gradient yellow exactly at the upper-left corner,
and blue exactly at the lower-right corner.</p>
<pre><code>linear-gradient(135deg, yellow, blue);
linear-gradient(-45deg, blue, yellow);</code></pre>
<p><img alt="" src=linear3.png></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(yellow, blue 20%, #0f0);</code></pre>
<p><img alt="" src=linear4.png></p>
</div>
<div class=example>
<p>This demonstrates* a corner-to-corner gradient specified with keywords.
Note how the gradient is red and blue exactly in the bottom-left and
top-right corners, respectively, exactly like the second example.
Additionally, the angle of the gradient is automatically computed so that
the color at 50% (in this case, white) stretches across the top-left and
bottom-right corners.</p>
<pre><code>linear-gradient(to top right, red, white, blue)</code></pre>
<p><object data=gradient1.svg height=100 width=200>(Image requires
SVG)</object></p>
<p><small>* SVG-in-HTML support required to view the image.</small></p>
</div>
<!-- ====================================================================== -->
<h3 id=radial-gradients><span class=secno>5.2. </span> Radial Gradients</h3>
<p>In a radial gradient, rather than colors smoothly fading from one side
of the box to the other as with linear gradients, they instead emerge from
a single point and smoothly spread outward in a circular or elliptical
shape.
<p>A radial gradient is specified by first pinpointing the <i>center</i> of
the gradient (where the 0% ellipse will be) then specifying the size and
shape of the <dfn id=ending-shape>ending-shape</dfn> (the 100% ellipse).
Color stops are given as a list, just as for ‘<code
class=css>linear-gradient()</code>’. Starting from the <i>center</i>
and progressing towards (and potentially beyond) the <a
href="#ending-shape"><i>ending-shape</i></a> concentric ellipses are drawn
and colored according to the specified color stops.</p>
<!-- ====================================================================== -->
<h4 class=no-toc id=radial-gradient-syntax><span class=secno>5.2.1. </span>
7B3C
radial-gradient() Syntax</h4>
<p>The radial gradient syntax is defined as follows:
<pre class=prod>
<dfn
id=ltradial-gradient><radial-gradient></dfn> = radial-gradient(
[ [ <shape> , ] |
[ <shape>? [ from <position> || to <extent> ] , ]
]?
<color-stop> [ , <color-stop> ]+
)</pre>
<p>The arguments are defined as follows:
<dl>
<dt><shape>
<dd>Can be either ‘<code class=css>circle</code>’ or
‘<code class=css>ellipse</code>’; determines whether the
gradient's <a href="#ending-shape"><i>ending-shape</i></a> is a circle or
an ellipse, respectively. If the <shape> is omitted it defaults to
‘<code class=css>ellipse</code>’.
<dt><position>
<dd>Determines the center of the gradient. The <position> is defined
as the positioning syntax of ‘<code class=css><a
href="http://www.w3.org/TR/css3-background/#the-background-position">background-position</a></code>’
and is resolved in the same way, using the center-point as the subject
and the content box as the positioning area. <a href="#CSS21"
rel=biblioentry>[CSS21]<!--{{!CSS21}}--></a> <a href="#CSS3BG"
rel=biblioentry>[CSS3BG]<!--{{!CSS3BG}}--></a> If this argument is
omitted, it defaults to ‘<code class=css>center</code>’.
<dt><extent>
<dd>
<p>Determines the size of the gradient's <a
href="#ending-shape"><i>ending-shape</i></a>. If omitted it defaults to
‘<code class=css>cover</code>’. It can be given explicitly
or by keyword. Possible keywords are:
<dl>
<dt><dfn id=radial-closest-side>‘<code
class=css>closest-side</code>’</dfn>
<dd>The <i>ending shape</i> is sized so that that it exactly meets the
side of the box closest to the gradient's center. If the shape is an
ellipse, it exactly meets the closest side in both dimensions.
<dt><dfn id=radial-farthest-side>‘<code
class=css>farthest-side</code>’</dfn>
<dd>Same as ‘<code class=css>closest-side</code>’, except
the <a href="#ending-shape"><i>ending-shape</i></a> is sized based on
the farthest side(s).
<dt><dfn id=radial-closest-corner>‘<code
class=css>closest-corner</code>’</dfn>
<dd>The <i>ending shape</i> is sized so that that it passes through the
side of the box closest to the gradient's center. If the shape is an
ellipse, the <a href="#ending-shape"><i>ending-shape</i></a> is given
the same aspect-ratio it would have if ‘<code
class=css>closest-side</code>’ were specified.
<dt><dfn id=radial-farthest-corner>‘<code
class=css>farthest-corner</code>’</dfn>
<dd>Same as ‘<code class=css>closest-corner</code>’, except
the <a href="#ending-shape"><i>ending-shape</i></a> is be sized based
on the farthest corner. If the shape is an ellipse, the <a
href="#ending-shape"><i>ending-shape</i></a> is given the same aspect
ratio it would have if ‘<code
class=css>farthest-side</code>’ were specified.
<dt><dfn id=radial-contain>‘<code
class=css>contain</code>’</dfn>
<dd>This value is an alias for ‘<code
class=css>closest-side</code>’, and has the same meaning.
<dt><dfn id=radial-cover>‘<code
class=css>cover</code>’</dfn>
<dd>This value is an alias for ‘<code
class=css>farthest-corner</code>’, and has the same meaning.
<dt><dfn id=radial-size>[<length> or
<percentage>]{1,2}</dfn>
<dd>Gives the size of the shape explicitly. The first value represents
the horizontal radius, the second the vertical radius. Percentages
values are relative to the corresponding dimension of the box. If only
one value is specified, both are the same. If the shape is specified to
be a circle, a ‘<code class=css>radial-gradient()</code>’
with two values is invalid. Negative values are also invalid.
</dl>
<p>Some combinations of position, size, and shape will produce a circle
or ellipse with a radius of 0. This will occur, for example, if the
center is on a box edge and ‘<code
class=css>closest-side</code>’ or ‘<code
class=css>closest-corner</code>’ is specified or if the size and
shape are given explicitly and either of the radiuses is zero. In these
instances, the gradient must be be rendered as follows:</p>
<dl>
<dt>If the <a href="#ending-shape"><i>ending-shape</i></a> has zero
width (regardless of the height):
<dd>Render as if the <a href="#ending-shape"><i>ending-shape</i></a> was
an ellipse whose height was an arbitrary very large number and whose
width was an arbitrary very small number greater than zero. <span
class=note>This will make the gradient look similar to a horizontal
linear gradien
4E88
t that is mirrored across the center of the ellipse. It
also means that all color-stop positions specified with a percentage
resolve to ‘<code class=css>0px</code>’.</span>
<dt>Otherwise, if the <a href="#ending-shape"><i>ending-shape</i></a>
has zero height:
<dd>Render as if the <a href="#ending-shape"><i>ending-shape</i></a> was
an ellipse whose width was an arbitrary very large number and whose
height was an arbitrary very small number greater than zero. <span
class=note>This will make the gradient look like a solid-color image
equal to the color of the last color-stop, or equal to the average
color of the gradient if it's repeating.</span>
</dl>
<p>Color-stops are placed on a <dfn id=gradient-ray>gradient-ray</dfn>,
similar to the <a href="#gradient-line"><i>gradient-line</i></a> of
linear gradients. The <a href="#gradient-ray"><i>gradient-ray</i></a> is
anchored at the center of the gradient and extends toward the right. The
0% location is at the start of the <a
href="#gradient-ray"><i>gradient-ray</i></a>, and the 100% location is
on the point where the <a href="#gradient-ray"><i>gradient-ray</i></a>
intersects the <a href="#ending-shape"><i>ending-shape</i></a>. Negative
locations can be specified; though negative locations are never directly
consulted for rendering, they can affect the color of non-negative
locations on the <a href="#gradient-ray"><i>gradient-ray</i></a> through
interpolation. For example, ‘<code class=css>radial-gradient(red
-50px, yellow 100px)</code>’ produces an elliptical gradient that