切换布局
显示结果
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>迹忆客(jiyik.com)</title> <style> div { border: 3px solid #4CAF50; padding: 5px; } .img1 { float: right; } .clearfix { overflow: auto; } .img2 { float: right; } </style> </head> <body> <p>以下实例图在父元素中溢出,很不美观:</p> <div> <img class="img1" src="/demo_source/pineapple.jpg" alt="Pineapple" width="170" height="170"> 迹忆客 - 分享的是技术,关注的是成长!!!</div> <p style="clear:right">在父元素上通过添加 clearfix 类,并设置 overflow: auto; 来解决该问题:</p> <div class="clearfix"> <img class="img2" src="/demo_source/pineapple.jpg" alt="Pineapple" width="170" height="170"> 迹忆客 - 分享的是技术,关注的是成长!!!</div> </body> </html>