content: attr(data-prefix);
@media print {
a[href]::after {
content: " (連結: " attr(href) ")";
font-size: 0.8em; color: #666;
}
}
新標準允許 attr(data-width px)、attr(data-color color) 等類型轉換,可直接用於 width、color 等屬性(瀏覽器支援度逐漸提升)。
body { counter-reset: heading; } /* 1. 重置計數器 */
h4::before {
counter-increment: heading; /* 2. 遞增 */
content: "第 " counter(heading) " 節 "; /* 3. 顯示 */
}
article { counter-reset: section; }
h2::before { counter-increment: section; content: counter(section) ". "; }
h3::before { counter-increment: subsection; content: counter(section) "." counter(subsection) " "; }
加 +、減 -、乘 *、除 /,可混合單位(px, %, em, rem, vw, vh...)。
.sidebar { width: 260px; float: left; }
.main { width: calc(100% - 260px); float: right; }
.card { padding: calc(1rem + 2vw); }
+ - 兩側**必須有空格**:calc(100% - 20px)。calc() 合法:calc(100% - calc(2em + 10px))。這三大函數讓 CSS 具備「讀取屬性、自動計數、數學運算」能力,大幅減少 JavaScript 介入,提升效能與可維護性。現代專案應優先採用。