You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p>The simplest way to indicate an image is to reference an image file by URL. This is done with the <ahref="http://www.w3.org/TR/CSS21/syndata.html#uri">''url()'' notation</a>, defined in [[!CSS21]].
215
214
216
215
<divclass="example">
217
216
<p>In the example below, a background image is specified with ''url()''
@@ -220,10 +219,7 @@ <h3 id="url">
220
219
<pre>background-image: url(wavy.png);</pre>
221
220
</div>
222
221
223
-
<p>A portion of an image may be referenced (clipped out and used as a
224
-
standalone image) by use of
225
-
<ahref="http://www.w3.org/TR/media-frags/#naming-space">media fragment identifiers</a>.
226
-
[[!MEDIA-FRAGS]]
8096
222
+
<p>A portion of an image may be referenced (clipped out and used as a standalone image) by use of <ahref="http://www.w3.org/TR/media-frags/#naming-space">media fragment identifiers</a>. [[!MEDIA-FRAGS]]
227
223
228
224
<divclass="example">
229
225
<p>For example, given the following image* and CSS:</p>
@@ -240,7 +236,63 @@ <h3 id="url">
240
236
<p><small>* SVG-in-<img> support required. Click the picture to view the SVG directly.</small></p>
241
237
</div>
242
238
243
-
<pclass="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 ''url''. A future level of this module is intended to introduce an alternate image-referencing function that is guaranteed to support image fragments.</p>
239
+
<pclass="note">Note that a legacy UA that doesn't understand the media
240
+
fragments notation will ignore the fragment and simply display the
241
+
entirety of an image specified with ''url''. However, since URLs with
242
+
media fragment identifiers can also be used in the ''image()'' notation
243
+
defined below, authors can take advantage of CSS's forward-compatible
244
+
parsing rules to provide a fallback when using an image fragment URL:</p>
245
+
246
+
<divclass="example">
247
+
<p>In the example below, the ''image()'' notation is used together with
248
+
the media fragment syntax, so that UAs that don't support media fragments
249
+
fail to parse the second declaration and use the first.</p>
250
+
251
+
<pre>
252
+
<!-- -->background-image: url('swirl.png'); /* old UAs */
253
+
<!-- -->background-image: image('sprites.png#xywh=10,30,60,20'); /* new UAs */</pre>
<p>The ''image()'' 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>
262
+
263
+
<p>So that authors can take advantage of CSS's forwards-compatible parsing
264
+
rules to provide a fallback for image slices, implementations that support
265
+
the ''image()'' notation <em>must</em> support the <code>xywh=#,#,#,#</code>
266
+
form of media fragment identifiers for images. [[!MEDIA-FRAGS]]
<p>Each <code><string></code> must be a URL.</p>
274
+
275
+
<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 'background-image', 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 <i>intrinsic dimensions</i>.
276
+
277
+
<divclass="example">
278
+
<p>The rule below would tell the UA to load ''wavy.svg'' if it can; failing that to load ''wavy.png''; failing that to display ''wavy.gif''; and finally, if none of the images can be loaded and displayed, to use the color ''rgba(0,0,255,0.5)'' 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>
<p>The 'background-size' property specifies that dimensionless images
283
+
by default stretch to cover the entire background positioning area
284
+
[[CSS3BG]], so if none of the specified images can be displayed
285
+
the background will be painted semi-transparent blue. As with any image,
286
+
this fallback will be painted over the 'background-color' (if any).</p>
287
+
</div>
288
+
289
+
<divclass='example'>
290
+
<p>At times, one may need a solid-color image for a property or function that does not accept the <color> type directly. The ''image()'' 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.
0 commit comments