Skip to content

Commit 2dc6623

Browse files
bramustabatkins
andauthored
[css-values-5] Define ident() (#11422)
* [css-values-5] Define ident() * [css-values-5] Link up relevant issue * [css-values-5] Fix dashed-ident example * [css-values-5] Fix view-transition-name ident() example * Update css-values-5/Overview.bs --------- Co-authored-by: Tab Atkins Jr. <jackalmage@gmail.com>
1 parent ae9bdf5 commit 2dc6623

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

css-values-5/Overview.bs

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1794,6 +1794,7 @@ Security</h4>
17941794
''--foo: attr(foo type(&lt;number&gt;)); background-image: src(string(var(--foo)))''
17951795
needs to be invalid as well.
17961796

1797+
17971798
<h4 id=attr-cycles>
17981799
Cycles</h4>
17991800

@@ -1856,6 +1857,83 @@ makes the containing [=declaration=] [=invalid at computed-value time=].
18561857
</pre>
18571858
</div>
18581859

1860+
<!-- Big Text: ident()
1861+
1862+
████ ████▌ █████▌ █ █▌ █████▌ ██ ██
1863+
▐▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ ▐█
1864+
▐▌ █▌ █▌ █▌ ██▌ █▌ █▌ █▌ ▐█
1865+
▐▌ █▌ █▌ ████ █▌▐█ █▌ █▌ █▌ ▐█
1866+
▐▌ █▌ █▌ █▌ █▌ ██▌ █▌ █▌ ▐█
1867+
▐▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ ▐█
1868+
████ ████▌ █████▌ █▌ ▐▌ █▌ ██ ██
1869+
-->
1870+
1871+
<h3 id=ident>
1872+
Constructing <<custom-ident>> values: the ''ident()'' function</h3>
1873+
1874+
<!-- https://github.com/w3c/csswg-drafts/issues/9141 -->
1875+
1876+
The <dfn>ident()</dfn> function is an [=arbitrary substitution function=]
1877+
that can be used to manually construct <<custom-ident>> values from several parts.
1878+
1879+
<pre class=prod>
1880+
<dfn function lt="ident()"><<ident()>></dfn> = ident( <<ident-arg>>+ )
1881+
<dfn><<ident-arg>></dfn> = <<string>> | <<integer>> | <<ident>>
1882+
</pre>
1883+
1884+
Issue(w3c/csswg-drafts#11426): Should we allow a fallback value?
1885+
1886+
The ''ident()'' function can be used as a value for any property or function argument
1887+
that accepts a <<custom-ident>>.
1888+
1889+
<div class=example>
1890+
In the following example,
1891+
each matched element gets a unique <dfn><<'view-timeline-name'>></dfn>
1892+
in the format of <code>"vtl-<em>number</em>"</code>.
1893+
The <code><em>number</em></code> is generated using ''sibling-index()''.
1894+
1895+
```css
1896+
.item {
1897+
/* vtl-1, vtl-2, vtl-3, … */
1898+
view-timeline-name: ident("vtl-" sibling-index());
1899+
}
1900+
```
1901+
</div>
1902+
1903+
While in many cases ''attr()'' with the <<attr-type>> set to <code>type(<<custom-ident>>)</code> will do,
1904+
''ident()'' can be used to construct a <<custom-ident>> using values that come from other elements.
1905+
1906+
<div class=example>
1907+
In the following example, the ''ident()'' function uses a custom property
1908+
which is defined on a parent.
1909+
1910+
```css
1911+
.card[id] {
1912+
/* E.g. card1, card2, card3, … */
1913+
--id: attr(id);
1914+
1915+
view-transition-name: ident(var(--id));
1916+
view-transition-class: card;
1917+
1918+
h1 {
1919+
/* E.g. card1-title, card2-title, card3-title, … */
1920+
view-transition-name: ident(var(--id) "-title");
1921+
view-transition-class: card-title;
1922+
}
1923+
}
1924+
```
1925+
</div>
1926+
1927+
To generate a <<dashed-ident>>, put <code>"--"</code> as the first argument.
1928+
1929+
<div class=example>
1930+
1931+
```css
1932+
.element {
1933+
anchor-name: ident("--" attr(id));
1934+
}
1935+
```
1936+
</div>
18591937

18601938
<!-- Big Text: random
18611939

0 commit comments

Comments
 (0)