标签:宽度自适应 float display inline-block
old:
<!DOCTYPE html> <html> <head> <style> .floating-box { float: left; width: 150px; height: 75px; margin: 10px; border: 3px solid #8AC007; } .after-box { clear: left; border: 3px solid red; } </style> </head> <body> <h2>The Old Way - using float</h2> <div class="floating-box">Floating box</div> <div class="floating-box">Floating box</div> <div class="floating-box">Floating box</div> <div class="floating-box">Floating box</div> <div class="floating-box">Floating box</div> <div class="floating-box">Floating box</div> <div class="floating-box">Floating box</div> <div class="floating-box">Floating box</div> <div class="after-box">Another box, after the floating boxes...</div> </body> </html>
new:
<!DOCTYPE html> <html> <head> <style> .floating-box { display: inline-block; width: 150px; height: 75px; margin: 10px; border: 3px solid #8AC007; } .after-box { border: 3px solid red; } </style> </head> <body> <h2>The New Way - using inline-block</h2> <div class="floating-box">Floating box</div> <div class="floating-box">Floating box</div> <div class="floating-box">Floating box</div> <div class="floating-box">Floating box</div> <div class="floating-box">Floating box</div> <div class="floating-box">Floating box</div> <div class="floating-box">Floating box</div> <div class="floating-box">Floating box</div> <div class="after-box">Another box, after the floating boxes...</div> </body> </html>
本文出自 “web之路” 博客,请务必保留此出处http://liuzhongcool.blog.51cto.com/10509488/1676342
标签:宽度自适应 float display inline-block
原文地址:http://liuzhongcool.blog.51cto.com/10509488/1676342