/* 方法一:轉為區塊元素 */
img { display: block; }
/* 方法二:垂直對齊 */
img { vertical-align: top; } /* 或 middle、bottom、text-top、text-bottom */
/* 方法三:父層字體歸零 */
.parent { font-size: 0; line-height: 0; }
a:link { color: #03c; }
a:visited { color: #666; }
a:hover { color: #f30; }
a:active { color: #c30; }
記住 LoVe HAte,順序錯誤會導致已訪問連結失去 hover 效果。
html { /* ✅ 設在 html,非 body */
scrollbar-face-color: #ddd;
scrollbar-track-color: #eee;
scrollbar-arrow-color: #000;
scrollbar-shadow-color: #eee;
scrollbar-highlight-color: #fff;
scrollbar-3dlight-color: #999;
scrollbar-darkshadow-color: #999;
}
⚠️ 非標準屬性,現代瀏覽器請用 scrollbar-color/scrollbar-width。
.nowrap { white-space: nowrap; width: 200px; overflow: hidden; }
.ellipsis {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
⚠️ Firefox 早期版本不支援,現代瀏覽器已全支援。
.break-word { word-wrap: break-word; } /* 舊屬性名,廣泛支援 */
.break-anywhere { overflow-wrap: anywhere; } /* 現代標準,更強力 */
a { outline: none; }
無障礙建議:a:focus { outline: 2px solid transparent; box-shadow: 0 0 0 2px #0066cc; }
| 模式 | 寬度計算 |
|---|---|
| 標準模式 | width = content + padding + border |
| 怪異模式 | width = content(含 padding+border) |
現代專案務必加 <!DOCTYPE html> 啟用標準模式,並全站 box-sizing: border-box。
input, textarea { ime-mode: disabled; }
⚠️ 非標準屬性,僅 IE/舊 Firefox 支援。現代建議用 inputmode 屬性。
禁用輸入法(行動裝置)。
<embed ... wmode="transparent" />
<param name="wmode" value="transparent" />
現代專案:Flash 已淘汰,改用 HTML5 <video>、<canvas>、WebGL。
<iframe allowtransparency="true" src="... "></iframe>
/* iframe 內頁面 */
body { background: transparent; }
副作用:透明 iframe 無法遮擋 <select> 下拉選單(IE6-7 z-index Bug)。
掌握兼容技巧後,建議學習 CSS 圓形頭像裁切實作,運用 border-radius 打造現代視覺元素。