如下

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="../css/test4.css">
</head>
<body>
<div class="box">
    <img src="./img/Snipaste_2022-06-25_20-39-26.png">
</div>
</body>
</html>

可见图片在div盒子下

.box {
    width: 298px;
    height: 415px;
    background-color: #ffffff;
    margin: 100px auto;
}
.box img {
    width: 100%;
}

**用width:100%**就可以让图片和盒子一样宽了!
image-1656161217030