img { display: block; } /* 轉塊級 */
img { vertical-align: top; } /* 或 middle/bottom/text-top/text-bottom */
.parent { font-size: 0; line-height: 0; } /* 父層字體歸零 */
推薦 display:block 或 vertical-align:middle,副作用最小。
a:link { color: #03c; }
a:visited { color: #666; }
a:hover { color: #f30; }
a:active { color: #c30; }
順序錯誤會導致狀態互相覆蓋失效。
html { /* 必須寫在 html,非 body */
scrollbar-face-color: #ddd;
scrollbar-track-color: #eee;
scrollbar-arrow-color: #000;
/* ...其他屬性 */
}
非標準屬性,僅 IE/Edge 舊版支援,現代專案建議自定義滾動條(::-webkit-scrollbar)或 JS 庫。
.ellipsis {
width: 150px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
三屬性締造單行省略號,Firefox 7+ 全支援。
.ellipsis-3 {
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
overflow: hidden;
}
.break-word { word-wrap: break-word; } /* 旧語法,別名 */
.break-word { overflow-wrap: break-word; } /* 標準語法 */
.break-all { word-break: break-all; } /* 字級斷行,中文慎用 */
a { outline: none; }
a:focus { outline: 2px solid #00f; } /* 保留無障礙焦點可見性 */
IE7- 需 onfocus="this.blur()",現代專案保留 focus 可見輪廓符合 WCAG。
| 模式 | width 計算 |
|---|---|
| 標準模式 | content-box:width = content,padding/border 向外擴展 |
| 怪異模式 | border-box:width = content + padding + border |
現代統一採用 box-sizing: border-box 全域化,消除模式差異。
input, textarea { ime-mode: disabled; }
非標準屬性,僅 IE/舊 Firefox 支援,現代建議 inputmode="numeric" 或 JS 控制。
<param name="wmode" value="transparent" />
<embed wmode="transparent" ... />
transparent 或 opaque 均可,HTML5 時代 Flash 已淘汰,僅供維舊參考。
<iframe allowtransparency="true" src="inner.html"></iframe>
/* inner.html body */
body { background: transparent; }
副作用:透明 Iframe 無法遮罩 <select> 等系統控件。