Skip to content

Commit 2e2bfc4

Browse files
andruudtabatkins
authored andcommitted
[css-properties-values-api] Explain how relative URLs work. (w3c#773)
See w3c#393, w3c#767.
1 parent 09b19df commit 2e2bfc4

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

css-properties-values-api/Overview.bs

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,10 +393,20 @@ For <length-percentage> values, the computed value is one of the following:
393393
* otherwise, the computed value is a calc expression containing an absolute
394394
length expressed in pixels, and a percentage value.
395395

396-
For <custom-ident>, ident, <color>, <image>, <url>, <integer>,
396+
For <custom-ident>, ident, <color>, <integer>,
397397
<angle>, <time>, <resolution> or "*" values, the
398398
computed value is as specified.
399399

400+
For <url> values, the computed value is one of the following:
401+
402+
* if the URL is a relative URL, the computed value is the resolved absolute URL
403+
as described in [[!css3-values]].
404+
* otherwise, the computed value is as specified.
405+
406+
For <image> values, the computed value is as specified, except that relative
407+
URLs that appear in the value are resolved to absolute URLs as described in
408+
[[!css3-values]].
409+
400410
For <number> and <percentage> values which are not calc expressions, the
401411
computed value is as specified. Calc expressions that are
402412
<number> and <percentage> values get reduced during computation to simple
@@ -473,6 +483,48 @@ ignored and any value consisting of at least one token is considered valid.
473483

474484
Issue(118): should @supports pay attention to type when considering custom properties?
475485

486+
Relative URLs {#relative-urls}
487+
------------------------------
488+
489+
Relative URL values that appear in registered custom properties are resolved
490+
to full URLs as described in [[!css3-values]].
491+
492+
<div class='example'>
493+
Because URLs resolve against the base URL of the stylesheet they appear in, we can
494+
end up with multiple relative URLs that resolve against different base URLs, even though
495+
they appear in the same property.
496+
497+
For example, suppose '--url-foo' and '--url-bar' are registered
498+
custom properties with ''&lt;url>'' syntax, and that we have a stylesheet at
499+
<code>/style/foo/foo.css</code>:
500+
501+
<pre class='lang-css'>
502+
div {
503+
--url-foo: url("foo.png");
504+
}
505+
</pre>
506+
507+
and another stylesheet at <code>/style/bar/bar.css</code>
508+
<pre class='lang-css'>
509+
div {
510+
--url-bar: url("bar.png");
511+
}
512+
</pre>
513+
514+
and finally a document at <code>/index.html</code>:
515+
<pre class='lang-html'>
516+
&lt;link href="/style/foo/foo.css" rel="stylesheet" type="text/css">
517+
&lt;link href="/style/bar/bar.css" rel="stylesheet" type="text/css">
518+
&lt;div style="background-image: var(--url-foo), var(---url-bar);">
519+
&lt;/div>
520+
</pre>
521+
522+
Here, the ''var(--url-foo)'' reference would produce a URL that resolves against
523+
<code>/style/foo</code>, and the ''var(--url-bar)'' reference would produce a URL that resolves
524+
against <code>/style/bar</code>.
525+
526+
</div>
527+
476528
Examples {#examples}
477529
====================
478530

0 commit comments

Comments
 (0)