image.png

代码

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>safari-flex-img</title>
  6. <style>
  7. .flex {
  8. display: flex;
  9. /*align-items: center;*/
  10. }
  11. .img {
  12. width: 30%;
  13. }
  14. </style>
  15. </head>
  16. <body>
  17. <img class="img" src="./haha.jpeg" alt="">
  18. <div class="flex">
  19. <img class="img" src="./haha.jpeg" alt="">
  20. </div>
  21. </body>
  22. </html>

解决方案

  1. 将 flex 下的 img 以 height 为基准,而不是 width。
  2. 将 flex 的包裹元素设置 align-items: center。