主页
CSS
CSS 浮动
示例
试试:并排浮动框
运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <head> <style> * { box-sizing: border-box; } .box { float: left; width: 33.33%; padding: 50px; } .clearfix::after { content: ""; clear: both; display: table; } </style> </head> <body> <h2>Grid of Boxes</h2> <p>Float boxes side by side:</p> <div class="clearfix"> <div class="box" style="background-color:#bbb"> <p>Some text inside the box.</p> </div> <div class="box" style="background-color:#ccc"> <p>Some text inside the box.</p> </div> <div class="box" style="background-color:#ddd"> <p>Some text inside the box.</p> </div> </div> <p><strong>Note:</strong> Here, we use the clearfix hack to take care of the layout flow. We also use the box-sizing property to make sure that the box doesn't break due to extra padding. Try to remove this code to see the effect.</p> </body> </html>