在 IE7 及以下,li 內的 <span class="time"> 設 float: right 時,會與前方的 <a> 錯位(一上一下),原因是 span.time 的 margin-top 莫名增加約 20px。
<li>
<span class="tag">[分類] </span>
<a href="...">新聞標題</a>
<span class="time">[2024-01-01]</span>
</li>
.time { float: right; }
.time {
float: right;
*margin-top: -20px; /* 只有 IE6/7 識別 * 前綴 */
}
| 目標瀏覽器 | 寫法範例 |
|---|---|
| 區別 IE6 / FF | background: orange; *background: blue; |
| 區別 IE6 / IE7 | background: green !important; background: blue; |
| 區別 IE7 / FF | background: orange; *background: green; |
| 同時區別 FF、IE7、IE6 | background: orange; *background: green; _background: blue; |
* 前綴:IE6/7 識別,標準瀏覽器忽略。_ 前綴:僅 IE6 識別。!important:IE7 支援,IE6 部分情況忽略。現代專案已無需支援 IE7 以下,建議採用 Flexbox/Grid 佈局,從根源避免浮動錯位。若必須維護舊專案,可將 Hack 集中於獨立 ie-legacy.css 並透過條件註釋引入。