我在IE9遇到了一個奇怪的問題,花了很多時間跟蹤和再現它。IE9負頂部邊緣 - 浮動和清除的孩子使元素卡住
因此,我們有以下標記:
<div class="container">
<div class="movable">
<div class="stuff">Stuff</div>
<div class="stuff special">Stuff Special</div>
<div class="stuff">Stuff</div>
<div class="stuff">Stuff</div>
</div>
</div>
這導致這樣的事情:
我們想移動的黃色框起來(從容器中)和使.stuff
元素清除。我們想漂浮至少一個.stuff
元素,我們選擇.special
,所以我們這樣做:
.movable { margin-top: -70px; }
.stuff { clear: both; }
.special { float: left; }
在左邊,結果我們得到的Chrome和Firefox,右側IE9:
正如你所看到的,IE9由於某種原因卡住施加負margin-top
,它總是會被卡住在右側或左側float
和clear: both;
上同時應用的元素。這兩個屬性的組合是必要的,只有其中一個不會觸發這種行爲。
A jsFiddle that demonstrates the problem and can be played with
這個問題已經出現在一個相當大的應用程序,因爲某些原因,我不能使用top
代替margin-top
,定位會破壞其他的東西。
有人有什麼想法如何幫助IE9正確顯示這個?
是否使用的是IE9的顛覆? – vbence 2013-04-30 18:02:39
版本:9.0.8112.16421,更新版本:9.0.15 – kapa 2013-04-30 18:04:05
在同一元素上應用清除和浮點操作是非常直觀的。漂浮後清除漂浮物。 – albert 2013-04-30 21:37:53