早期無 border-radius 時,開發者採用:
<b> 模擬漸變** — 利用 margin + border 疊加 1px 高條帶,形成「近似圓弧」(文中 .r1-.r4 方案)。缺點顯而易見:標籤污染嚴重、放大可見鋸齒、性能差、不支援背景圖/漸變。
border-radius 一行搞定.card {
border-radius: 12px; /* 統一圓角 */
border-radius: 8px 16px; /* 左上/右下、右上/左下 */
border-radius: 8px 16px 24px 32px; /* 四角分別指定 */
border-radius: 50%; /* 圓形/橢圓 */
border-radius: 100px / 50px; /* 水平/垂直半徑不同(橢圓弧) */
}
.card { overflow: hidden; border-radius: 12px; } /* 子元素超出圓角會被裁切 */
border 遵循圓角曲線。box-shadow 同樣跟隨圓角(無需額外設定)。outline **不跟隨圓角**(始終矩形),勿用於圓角元素聚焦態。table { border-collapse: collapse; border-radius: 12px; overflow: hidden; }
/* 必須 collapse + overflow:hidden 才生效 */
.organic-shape {
border-radius: 40% 60% 60% 40% / 60% 40% 60% 40%;
/* 八值:左上水平 右上水平 右下水平 左下水平 / 左上垂直 右上垂直 右下垂直 左下垂直 */
}
從幾十個 <b> 標籤模擬鋸齒,到一行 border-radius 完美圓角,CSS 發展史就是「用更少代碼做更酷事情」的歷史。**拋棄舊技巧,擁抱標準**,才是最高效的圓角方案。