hasLayout 是 IE 渲染引擎內部屬性(true/false),決定元素是否「擁有版面配置權」。擁有 layout 的元素自行計算尺寸、定位子孫元素;無 layout 元素依賴祖先元素計算。
hasLayout = -1 表示擁有 layout。body, htmltable, tr, th, tdimg, hrinput, button, select, textarea, fieldsetmarquee, iframe, embed, object, applet其餘元素(如 div, span, p)預設 無 layout,為了效能與簡潔。
| 屬性 | 值條件 | 適用版本 |
|---|---|---|
display | inline-block | IE5.5+ |
width / height | 任意值(除 auto) | IE6 標準模式下內聯元素無效 |
float | left | right | IE6+ |
position | absolute / fixed (IE7+) | IE6+ / IE7+ |
writing-mode | tb-rl | IE6+ |
zoom | 除 normal 外任意值 | IE5.5+ (IE5.0 不支援) |
min-height / max-height | 任意值 / 非 none | IE7+ |
min-width / max-width | 任意值 / 非 none | IE7+ |
overflow / overflow-x/y | 非 visible | IE7+ |
| Bug 名稱 | 現象 | 修復(觸發 hasLayout) |
|---|---|---|
| 雙邊距浮動 Bug (IE6) | 浮動元素邊距加倍 | display: inline; |
| 3px 間隙 Bug (IE5-6) | 浮動元素旁 3px 間隙 | _height: 1%; (Holly Hack) |
| 躲躲貓 Bug (IE6) | 內容滾動時消失/閃爍 | _height: 1%; 或 zoom: 1; |
zoom: 1;(不影響視覺、不觸發副作用)。width/height 明確尺寸;次選 overflow: hidden、float、display: inline-block;最後才用 zoom: 1。_height: 1%;(底線 hack)或條件註解載入修正樣式。min-height: 0;(不影響視覺、穩定觸發)。擁有 layout 的內聯元素表現類似標準 inline-block:水平排列、受 vertical-align 影響、尺寸隨內容自適應。這解釋為何 IE 允許內聯元素包含區塊元素較少出錯。
<!--[if lt IE 9]>...<![endif]--> 載入修正樣式。