首页
CSS
CSS 浮动
示例
实战:并排浮动图像
运行 ❯
获取您自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <head> <style> * { box-sizing: border-box; } .img-container { float: left; width: 33.33%; padding: 5px; } .clearfix::after { content: ""; clear: both; display: table; } </style> </head> <body> <h2>Images Side by Side</h2> <p>Float images side by side:</p> <div class="clearfix"> <div class="img-container"> <img src="img_5terre.jpg" alt="Italy" style="width:100%"> </div> <div class="img-container"> <img src="img_forest.jpg" alt="Forest" style="width:100%"> </div> <div class="img-container"> <img src="img_mountains.jpg" alt="Mountains" style="width:100%"> </div> </div> <p>Note that we also use the clearfix hack to take care of the layout flow, and that we add the box-sizing property to make sure that the image container doesn't break due to extra padding. Try to remove this code to see the effect.</p> </body> </html>