一位朋友告訴我,正確的浮動元素應該先出現在我的文檔中,但我想我誤解了他想告訴我的內容,我想知道是否有人可以解釋爲什麼如果我同時擁有正確的浮動divs第一個左浮動的div被清除並且在第一個右浮動div後出現在線上?Css浮動元素
這裏是那不執行,因爲我想(2左2右浮動彼此相鄰堆)
<div style="margin-left: auto; margin-right: auto; height: 600px; border: 1px solid black">
<div style="width: 200px; height: 200px; background-color: red; float:right;"></div>
<div style="width: 200px; height: 200px; background-color: green; float:right; clear: right"></div>
<div style="width: 200px; height: 200px; background-color: yellow; float:left; clear: none"></div>
<div style="width: 200px; height: 200px; background-color: purple; float:left; clear: left"></div>
</div>
在這裏,它的作品,因爲我會想,但一個片段我不得不在文檔中四處移動元素的順序:
<div style="margin-left: auto; margin-right: auto; height: 600px; border: 1px solid black">
<div style="width: 200px; height: 200px; background-color: red; float:right;"></div>
<div style="width: 200px; height: 200px; background-color: yellow; float:left; clear: none"></div>
<div style="width: 200px; height: 200px; background-color: green; float:right; clear: right"></div>
<div style="width: 200px; height: 200px; background-color: purple; float:left; clear: left"></div>
</div>
對不起,如果這已經得到了答案,我確定這是一個簡單的問題要回答,我想知道爲什麼我需要正確的浮動,左浮動,但接下來的浮動它似乎不重要,如果正確或左浮動第一。
感謝
兩個小提琴都顯示相同的結果 – Sharun 2013-03-27 10:38:14
@slacker不知道爲什麼我的不同; – egig 2013-03-27 10:41:16
好的,我一定錯過了一些東西......我只是試着將這些例子粘貼到Firefox 19.0.02中,他們看起來不一樣。編輯我剛剛在IE 8中嘗試,他們看起來一樣。 – berimbolo 2013-03-27 10:42:21