形式 | attr(<attr-name> <attr-type>? [, <fallback>]) |
---|---|
値の詳細 | <attr-type> = <attr-unit> | string | type(<syntax>) |
サポート | https://caniuse.com/?search=attr() |
要素の属性値を参照します。Chrome 133 ですべてのプロパティに対応しましたが、他のブラウザではまだ content のみで使用可能です。
type(<color>)
のように指定します。型には string, color, url, integer, number, length, angle, time, frequency を指定します。Chrome 133 でサポートされました。(サポート状況)a[href]::after { font-size: 80%; content: " (" attr(href) ")"; }
<a href="http://www.tohoho-web.com">とほほのWWW入門</a>
[data-size] { font-size: attr(data-size px); } [data-color] { color: attr(data-color type(<color>), blue); }
<div data-size="64">AAAA</div> <div data-color="red">AAAA</div>