float left和right同时在一行换行问题

例如:

<div style="float: left; width: 150px; height: 150px;">浮动元素1</div>
<div style="float: right; width: 150px; height: 150px;">浮动元素2 </div>


但是你会发现“浮动元素2”换行了。


解决办法:将float:right放在left前面。

<div style="float: right; width: 150px; height: 150px;">浮动元素2 </div>

<div style="float: left; width: 150px; height: 150px;">浮动元素1</div>
<div style="clear:both"></div>