透過CSS定義屬性,自訂html元素屬性值。
ps.目前有瀏覽器支援度問題
☞ 語法說明
/* Simple usage */ attr(data-count); attr(title); /* With type */ attr(src url); attr(data-count number); attr(data-width px); /* With fallback */ attr(data-count number, 0); attr(src url, ''); attr(data-width px, inherit); attr(data-something, 'default');
☞ 範例
自訂屬性值 ::before
/* css範例-自訂屬性值 */ p::before { content: attr(data-foo) " "; }
<p data-foo="hello">world</p>
自訂屬性值 ::after
/* css範例-自訂屬性值 */ span:hover::after { content: attr(data-title); }
<span data-title="提示">按钮</span>