I can't understand, why I should use display: flex;
to get the image stretched for the whole space. Even if I set height of the img
tag and for its parent (.hey
) to 100%
, it won't work and would have white space.
Here's the code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body {
background-color: bisque;
}
.wrapper {
display: flex;
flex-direction: row;
}
img {
width: 100%;
height: 100%;
}
.hey {
/* If we won't place display: flex; the image height won't be affected and white space would occur */
/* display: flex; */
height: 100%;
}
.dance {
background-color: aqua;
}
@media screen and (max-width: 768px) {
.wrapper {
flex-direction: column;
}
}
</style>
<title>Document</title>
</head>
<body>
<div class="wrapper">
<div class="hey"><img src="./img/blog/blog2.jpg" alt=""></div>
<div class="dance">
<h4>Hey</h4>
<p>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Sapiente rerum aliquid tempora ipsum facere
neque, sint expedita nihil laboriosam accusantium.</p>
</div>
</div>
</body>
</html>
Can you please explain why it works that way?