Skip to content

Commit ba9fa30

Browse files
committed
[css-values-5] Define ident()
1 parent 2f1a48a commit ba9fa30

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

css-values-5/Overview.bs

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1791,6 +1791,94 @@ Security</h4>
17911791
''--foo: attr(foo type(&lt;number&gt;)); background-image: src(string(var(--foo)))''
17921792
needs to be invalid as well.
17931793

1794+
<!-- Big Text: ident()
1795+
1796+
████ ████▌ █████▌ █ █▌ █████▌ ██ ██
1797+
▐▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ ▐█
1798+
▐▌ █▌ █▌ █▌ ██▌ █▌ █▌ █▌ ▐█
1799+
▐▌ █▌ █▌ ████ █▌▐█ █▌ █▌ █▌ ▐█
1800+
▐▌ █▌ █▌ █▌ █▌ ██▌ █▌ █▌ ▐█
1801+
▐▌ █▌ █▌ █▌ █▌ █▌ █▌ █▌ ▐█
1802+
████ ████▌ █████▌ █▌ ▐▌ █▌ ██ ██
1803+
-->
1804+
1805+
<h3 id=ident>
1806+
Constructing <<custom-ident>> values: the ''ident()'' function</h3>
1807+
1808+
<!-- https://github.com/w3c/csswg-drafts/issues/9141 -->
1809+
1810+
The <dfn>ident()</dfn> function is an [=arbitrary substitution function=]
1811+
that can be used to manually construct <<custom-ident>> values from several parts.
1812+
1813+
<pre class=prod>
1814+
<dfn><<ident-fn>></dfn> = ident(<<ident-args>>);
1815+
<dfn><<ident-args>></dfn> = [<<string>> | <<integer>> | <<ident>>]+
1816+
</pre>
1817+
1818+
Issue: Should we allow a fallback value?
1819+
1820+
The ''ident()'' function can be used as a value for any property or function argument
1821+
that accepts a <<custom-ident>>.
1822+
1823+
<div class=example>
1824+
In the following example,
1825+
each matched element gets a unique <dfn><<'view-timeline-name'>></dfn>
1826+
in the format of <code>"vtl-<em>number</em>"</code>.
1827+
The <code><em>number</em></code> is generated using ''sibling-index()''.
1828+
1829+
```css
1830+
.item {
1831+
/* vtl-1, vtl-2, vtl-3, … */
1832+
view-timeline-name: ident("vtl-" sibling-index());
1833+
}
1834+
```
1835+
</div>
1836+
1837+
While in many cases ''attr()'' with the <<attr-type>> set to <code>type(<<custom-ident>>)</code> will do,
1838+
''ident()'' can be used to construct a <<custom-ident>> using values that come from other elements.
1839+
1840+
<div class=example>
1841+
In the following example, the ''ident()'' function uses a custom property
1842+
which is defined on a parent.
1843+
1844+
```css
1845+
.card[id] {
1846+
/* E.g. card1, card2, card3, … */
1847+
--id: attr(id);
1848+
1849+
view-transition-name: var(--id);
1850+
view-transition-class: card;
1851+
1852+
h1 {
1853+
/* E.g. card1-title, card2-title, card3-title, … */
1854+
view-transition-name: ident(var(--id) "-title");
1855+
view-transition-class: card-title;
1856+
}
1857+
}
1858+
```
1859+
</div>
1860+
1861+
To generate a <<dashed-ident>>, put <code>"--"</code> as the first argument.
1862+
1863+
<div class=example>
1864+
1865+
```css
1866+
.card[id] {
1867+
/* E.g. card1, card2, card3, … */
1868+
--id: attr(id);
1869+
1870+
view-transition-name: var(--id);
1871+
view-transition-class: card;
1872+
1873+
h1 {
1874+
/* E.g. card1-title, card2-title, card3-title, … */
1875+
view-transition-name: ident(var(--id) "-title");
1876+
view-transition-class: card-title;
1877+
}
1878+
}
1879+
```
1880+
</div>
1881+
17941882
<!-- Big Text: random
17951883

17961884
████▌ ███▌ █ █▌ ████▌ ███▌ █ █

0 commit comments

Comments
 (0)