Skip to content

Commit acf3ab1

Browse files
committed
[css-values] Per f2f resolution, add special 'guaranteed to be a local ref' handling of fragment-only URLs.
1 parent fb7b971 commit acf3ab1

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

css-values/Overview.bs

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Editor: fantasai, http://fantasai.inkedblade.net/contact
2222
Former Editor: Håkon Wium Lie, Opera Software, howcome@opera.com
2323
Abstract: This CSS3 module describes the common values and units that CSS properties accept and the syntax used for describing them in CSS property definitions.
2424
At Risk: ''toggle()'', ''attr()''
25-
Ignored Terms: <spacing-limit>, containing block
25+
Ignored Terms: <spacing-limit>, containing block, linear-gradient
2626
Ignored Vars: Cn+1, n
2727
</pre>
2828
<pre class='link-defaults'>
@@ -574,6 +574,54 @@ Relative URLs</h4>
574574
The same image will be used regardless of the URL of the source document containing the <code>&lt;body></code>.
575575
</div>
576576

577+
<h4 id='local-urls'>
578+
Fragment URLs</h4>
579+
580+
In some CSS-using languages like SVG,
581+
one often needs to refer to elements in the host document directly
582+
(such as to reference a <{linear-gradient}> element).
583+
To facilitate this and work around some common eccentriticites in browser URL handling,
584+
CSS has special behavior for fragment-only urls.
585+
586+
If a ''url()''’s value starts with a U+0023 NUMBER SIGN (<code>#</code>) character,
587+
parse it as per normal for URLs,
588+
but additionally set the <dfn export for="url()">local url flag</dfn> of the ''url()''.
589+
590+
When matching a ''url()'' with the <a>local url flag</a> set,
591+
ignore everything but the URL's fragment,
592+
and resolve that fragment against the host document.
593+
This reference must always be treated as same-document
594+
(rather than cross-document).
595+
596+
Note: This means that an SVG reference like ''url(#my-gradient)''
597+
will work the same whether the CSS is written inline in the SVG document
598+
or linked in as an external CSS stylesheet.
599+
600+
When serializing a ''url()'' with the <a>local url flag</a> set,
601+
it must serialize as just the fragment.
602+
603+
<details class=note>
604+
<summary>What "browser eccentricities"?</summary>
605+
606+
Theoretically, browsers should re-resolve any relative URLs,
607+
including fragment-only URLs,
608+
whenever the document's base URL changes
609+
(such as through mutation of the <{base}> element,
610+
or calling {{History/pushState()}}).
611+
In many cases they don't, however,
612+
and so without special handling,
613+
fragment-only URLs will suddenly become cross-document references
614+
(pointing at the previous base URL)
615+
and break in many of the places they're used.
616+
617+
Refusing to re-resolve relative URLs makes sense in many cases
618+
(it will usually give the <em>desired</em> behavior
619+
when the URL is path-relative),
620+
but fragment-only URLs express a clear semantic
621+
of wanting to refer to the current document
622+
regardless of what its URL is.
623+
</details>
624+
577625
<h4 id='url-modifiers'>
578626
URL Modifiers</h4>
579627

0 commit comments

Comments
 (0)