浮动前
三个左浮
<style> .tt{ border: darkcyan 3px solid; overflow: hidden; } .left , .right{ width: 100px; height: 100px; border: 3px double blue; } .left{ border: yellow solid 3px; background-color: darkcyan; float: left; } .right{ background-color: tomato; float: left; } .qq{ border: 3px groove sienna; width: 100px; height: 100px; background-color: grey; float: left; } </style> </head> <body> <div class="tt"> <div class="left">left</div> <div class="right">right</div> <div class="qq">qq</div> </div>
备注:
浮动过程中出现高度坍塌
在边框描述中添加:
overflow: hidden; 消除坍塌
或者等效方法
<style> .tt{ border: darkcyan 3px solid; /* overflow: hidden;*/ } .clearfix:after{ display: block; clear:both; content:""; } .left , .right{ width: 100px; height: 100px; border: 3px double blue; } .left{ border: yellow solid 3px; background-color: darkcyan; float: right; } .right{ background-color: tomato; float: right; } .qq{ border: 3px groove sienna; width: 100px; height: 100px; background-color: grey; float: right; } </style> </head> <body> <div class="tt clearfix" > <div class="left">left</div> <div class="right">right</div> <div class="qq">qq</div> </div> </body>