一、對父級設置適合CSS高度,代碼展現以下:html
<style> .div_01{ width:400px; border:1px solid #F00; background:#FF0; height:102px; } .div_01-left,.div_02-right{ width:180px; height:100px; border:1px solid #00F; background:#FFF; } .div_01-left{ float:left; } .div_02-right{ float:right; } </style> <div class="div01"> <div class="div_01-left">left浮動</div> <div class="div_01-right">right浮動</div> </div>
二、clear:both清除浮動,代碼展現以下:code
<style> .div_01{ width:400px; border:1px solid #F00; background:#FF0; } .div_01-left,.div_02-right{ width:180px; height:100px; border:1px solid #00F; background:#FFF; } .div_01-left{ float:left; } .div_02-right{ float:right; } .clear{ clear:both; } </style> <div class="div01"> <div class="div_01-left">left浮動</div> <div class="div_01-right">right浮動</div> <div class="clear"></div> </div>
三、父級div定義 overflow:hiddenhtm
<style> .div_01{ width:400px; border:1px solid #F00; background:#FF0; overflow:hidden; } .div_01-left,.div_02-right{ width:180px; height:100px; border:1px solid #00F; background:#FFF; } .div_01-left{ float:left; } .div_02-right{ float:right; } </style> <div class="div01"> <div class="div_01-left">left浮動</div> <div class="div_01-right">right浮動</div> </div>