Skip to content

Commit c6b60a3

Browse files
committed
[css-properties-values-api] Move the Relative URLs section to be an example under the 'Computed Value'->'URLs' section.
1 parent b375955 commit c6b60a3

File tree

1 file changed

+45
-41
lines changed

1 file changed

+45
-41
lines changed

css-properties-values-api/Overview.bs

+45-41
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,51 @@ the computed value is one of the following:
244244
the computed value is the resolved absolute URL as described in [[!css3-values]].
245245
* otherwise, the computed value is as specified.
246246

247+
<details class=note>
248+
<summary>URL behavior examples</summary>
249+
<div class='example'>
250+
Because URLs resolve against the base URL of the stylesheet they appear in, we can
251+
end up with multiple relative URLs that resolve against different base URLs, even though
252+
they appear in the same property.
253+
254+
For example, suppose '--url-foo' and '--url-bar' are registered
255+
custom properties with ''&lt;url>'' syntax, and that we have a stylesheet at
256+
<code>/style/foo/foo.css</code>:
257+
258+
<pre class='lang-css'>
259+
div {
260+
--url-foo: url("foo.png");
261+
}
262+
</pre>
263+
264+
and another stylesheet at <code>/style/bar/bar.css</code>
265+
<pre class='lang-css'>
266+
div {
267+
--url-bar: url("bar.png");
268+
}
269+
</pre>
270+
271+
and finally a document at <code>/index.html</code>:
272+
<pre class='lang-html'>
273+
&lt;link href="/style/foo/foo.css" rel="stylesheet" type="text/css">
274+
&lt;link href="/style/bar/bar.css" rel="stylesheet" type="text/css">
275+
&lt;div style="background-image: var(--url-foo), var(---url-bar);">
276+
&lt;/div>
277+
</pre>
278+
279+
Here, the ''var(--url-foo)'' reference would produce a URL that resolves against
280+
<code>/style/foo</code>, and the ''var(--url-bar)'' reference would produce a URL that resolves
281+
against <code>/style/bar</code>.
282+
283+
On the other hand,
284+
if both '--url-foo' and '--url-bar' were <em>un</em>registered,
285+
they would substitute their literal values
286+
(relative URLs)
287+
into the <code>/index.html</code> stylesheet,
288+
which would then resolve the URLs against <code>/index.html</code> instead.
289+
</div>
290+
</details>
291+
247292
For <code>"&lt;image>"</code> values,
248293
the computed value is the [=computed &lt;image>=].
249294

@@ -312,47 +357,6 @@ but be automatically [=invalid at computed-value time=].
312357
As ''@supports'' tests parsing behavior,
313358
it thus also accepts all values as valid regardless of the registered syntax.
314359

315-
Relative URLs {#relative-urls}
316-
------------------------------
317-
318-
Relative URL values that appear in registered custom properties are resolved
319-
to full URLs as described in [[!css3-values]].
320-
321-
<div class='example'>
322-
Because URLs resolve against the base URL of the stylesheet they appear in, we can
323-
end up with multiple relative URLs that resolve against different base URLs, even though
324-
they appear in the same property.
325-
326-
For example, suppose '--url-foo' and '--url-bar' are registered
327-
custom properties with ''&lt;url>'' syntax, and that we have a stylesheet at
328-
<code>/style/foo/foo.css</code>:
329-
330-
<pre class='lang-css'>
331-
div {
332-
--url-foo: url("foo.png");
333-
}
334-
</pre>
335-
336-
and another stylesheet at <code>/style/bar/bar.css</code>
337-
<pre class='lang-css'>
338-
div {
339-
--url-bar: url("bar.png");
340-
}
341-
</pre>
342-
343-
and finally a document at <code>/index.html</code>:
344-
<pre class='lang-html'>
345-
&lt;link href="/style/foo/foo.css" rel="stylesheet" type="text/css">
346-
&lt;link href="/style/bar/bar.css" rel="stylesheet" type="text/css">
347-
&lt;div style="background-image: var(--url-foo), var(---url-bar);">
348-
&lt;/div>
349-
</pre>
350-
351-
Here, the ''var(--url-foo)'' reference would produce a URL that resolves against
352-
<code>/style/foo</code>, and the ''var(--url-bar)'' reference would produce a URL that resolves
353-
against <code>/style/bar</code>.
354-
355-
</div>
356360

357361
Substitution via ''var()'' {#substitution}
358362
------------------------------------------

0 commit comments

Comments
 (0)