代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>safari-flex-img</title>
<style>
.flex {
display: flex;
/*align-items: center;*/
}
.img {
width: 30%;
}
</style>
</head>
<body>
<img class="img" src="./haha.jpeg" alt="">
<div class="flex">
<img class="img" src="./haha.jpeg" alt="">
</div>
</body>
</html>
解决方案
- 将 flex 下的 img 以 height 为基准,而不是 width。
- 将 flex 的包裹元素设置 align-items: center。