I'm finding it challenging to grasp the various image size settings in Flexbox. It seems like every time I try to apply them, I end up with a different outcome.
Instead of just saying "it depends on the situation," can someone provide a logical explanation that connects these different scenarios? I want to understand why the results vary each time, particularly in terms of image placement based on viewport size. Let's assume I am using object-fit: cover for all cases. Here's an example featuring two images side by side.
index.html
<section>
<figure>
<img src="profile image1.jpg" alt="">
</figure>
<figure>
<img src="profile image2.jpg" alt="">
</figure>
</section>
style.css
section {
display: flex;
}
Scenario 1
style.css
/* set the figure wrapper's dimensions only */
figure {
flex: 50%;
width: 100%;
height: auto;
}
Scenario 2
style.css
/* set both the figure wrapper and image dimensions as percentages */
figure {
flex: 50%;
width: 100%;
height: auto;
}
img {
width: 100%;
height: 100%;
}
Scenario 3
style.css
/* set both the figure wrapper and image dimensions in pixels */
figure {
flex: 50%;
width: 400px;
height: 400px;
}
img {
width: 400px;
height: 400px;
}
Scenario 4
style.css
/* set the figure's dimensions with max-width and max-height */
figure {
flex: 50%;
max-width: 400px;
max-height: 400px;
}
img {
width: 100%;
height: 100%;
}
Scenario 5
style.css
/* set both the figure and image dimensions with max-width and max-height */
figure {
flex: 50%;
max-width: 400px;
max-height: 400px;
}
img {
max-width: 100%;
max-height: 100%;
}
I am trying to understand the advantages of placing the image within a container with varying configurations of pixel or percentage dimension units.