早期圓角需用背景圖片、多層巢狀標籤甚至 JavaScript 實現。CSS3 border-radius 讓圓角成為原生樣式,所有現代瀏覽器完美支援。
.rounded {
border-radius: 10px; /* 四角同半徑 */
border-radius: 10px 20px; /* 左上/右下 10px、右上/左下 20px */
border-radius: 10px 20px 30px;/* 左上 10px、右上/左下 20px、右下 30px */
border-radius: 10px 20px 30px 40px; /* 順時針:左上、右上、右下、左下 */
}
亦可分別設定水平/垂直半徑(橢圓角):
.oval {
border-radius: 50px / 20px; /* 水平半徑 50px、垂直半徑 20px */
}
.custom-corner {
border-top-left-radius: 10px;
border-top-right-radius: 20px;
border-bottom-right-radius: 30px;
border-bottom-left-radius: 40px;
}
.legacy-support {
-webkit-border-radius: 10px; /* Safari 4-, Android 2.3- */
-moz-border-radius: 10px; /* Firefox 3.6- */
-khtml-border-radius: 10px; /* Konqueror 等舊核心 */
border-radius: 10px; /* 標準語法置最後 */
}
現代專案建議:直接使用標準 border-radius,透過 Autoprefixer 自動處理極少數舊版瀏覽器需求。
border-radius: 50% 搭配等寬高容器border-radius: 9999px 或 100vh 確保任意寬度皆圓角border-radius: 30% 70% 70% 30% / 30% 30% 70% 70% 繪製有機形狀overflow: hidden 或 background-clip: padding-boxbox-shadow: 0 0 0 2px color 模擬邊框,避免圓角邊框渲染異常table { border-collapse: separate; border-spacing: 0; } 並對 th/td 套用半徑