在日曆專案按鈕上同時使用 border-radius(圓角)、box-shadow(陰影)、rgba()(半透明色),發現各瀏覽器渲染差異極大,尤其 Chrome 出現圓角外溢方形邊角的 Bug。
#cal td.smd_cal_event span a {
background: #fab102;
padding: 4px 10px 5px 10px;
border: 1px solid #fff;
border-bottom: 1px solid #363d50;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
border-radius: 10px;
-moz-box-shadow:
inset 0 4px 7px 0 #fff25f,
inset 0 -2px 4px 0 rgba(255,242,94,0.4),
inset 0 -4px 8px 0 rgba(207,75,3,0.9),
0 2px 4px 0 rgba(0,0,0,0.4);
-webkit-box-shadow:
inset 0 4px 7px 0 #fff25f,
inset 0 -2px 4px 0 rgba(255,242,94,0.4),
inset 0 -4px 8px 0 rgba(207,75,3,0.9),
0 2px 4px 0 rgba(0,0,0,0.4);
box-shadow:
inset 0 4px 7px 0 #fff25f,
inset 0 -2px 4px 0 rgba(255,242,94,0.4),
inset 0 -4px 8px 0 rgba(207,75,3,0.9),
0 2px 4px 0 rgba(0,0,0,0.4);
}
| 瀏覽器 | 圓角 | 內陰影 | 外陰影 | RGBa | 綜合評價 |
|---|---|---|---|---|---|
| IE7 | ✗ | ✗ | ✗ | ✗ | 完全不支援 CSS3 視覺屬性 |
| IE8 | ✗ | ✗ | ✗ | ✗ | 同上 |
| Safari 4/5 | ✓ | ✗ (不支援 inset) | ✓ (需調整順序) | ✓ | 外陰影需寫在 inset 前,否則全失效 |
| Chrome 4/5 | ✓ | ✗ (渲染錯誤:方形邊角外溢) | △ (需 ≥4px 模糊半徑) | ✓ | 嚴重 Bug:border-radius + inset box-shadow 導致邊角溢出 |
| Firefox 3.6 | ✓ 最佳 | ✓ 完美 | ✓ 完美 | ✓ | 曲線最平滑,內陰影分佈最均勻,首選 |
| Opera 10.5 | ✓ 優秀 | ✓ 優秀 | ✓ 優秀 | ✓ | 緊隨 Firefox,表現極佳 |
inset box-shadow,改用漸層模擬內部立體感。border-radius + overflow: hidden,內層套用 box-shadow。::before 絕對定位覆蓋,套用陰影與圓角,pointer-events: none。將外陰影寫在 inset 之前,並移除擴展陰影語句:
-webkit-box-shadow:
0 2px 4px rgba(0,0,0,0.4), /* 外陰影優先 */
inset 0 4px 7px 0 #fff25f,
inset 0 -2px 4px 0 rgba(255,242,94,0.4),
inset 0 -4px 8px 0 rgba(207,75,3,0.9);
此順序下 Safari 能渲染外陰影與部分內陰影效果。
上述 CSS 約 700 bytes(含廠商前綴);等效背景圖片輕易達 6-7KB,另需 1 個 HTTP 請求。CSS 繪製在維護性、擴展性、效能上均優於圖片。
@supports 或 Modernizr 做特性檢測,優雅降級。