I have a bunch of divs that I laid out next to each other (depending upon window size there are 2-4 per "row"). Inside these divs, I added some wrappers and such, but at the center of each div there is an image that only has its width (not height) property set via CSS. The odd thing that was happening was that images with a greater width than height in the original png caused the outermost div containing it to shift down. I searched for a solution for a while and found that setting overflow: auto;
in the divs with class "item-card-wrapper" (see below) somehow magically fixed the layout. I thought I understood how overflow works, but I am so confused as to how it seemed to magically fix the issue (and this isn't the only instance in which this has happened for me).
The only "correct" div here is the one that sticks out from the rest. When I added overflow: auto;
it was fixed:
Here is the HTML (I clipped it early because it just starts repeating itself for each "square"):
<div id="shop">
<div id="shop-center-wrapper">
<div class="item-card-wrapper" style="width: 25%; min-width: 200px;">
<div class="item-card" style="height: 245px;">
<div class="image-wrapper">
<img class="image" src="static/products/Three Kings Glow.png">
</div>
</div>
</div>
<div class="item-card-wrapper" style="width: 25%; min-width: 200px;">
<div class="item-card" style="height: 245px;">
<div class="image-wrapper">
<img class="image" src="static/products/Amor Azul.png">
</div>
</div>
</div>
...
And here are the relevant CSS classes:
#shop {
margin-top: 40px;
margin-left: 50px;
margin-right: 50px;
overflow: auto;
}
#shop-center-wrapper {
text-align: center;
margin: 0px auto;
}
.item-card-wrapper {
margin-top: 20px;
margin-bottom: 20px;
display: inline-block;
overflow: auto;
}
.item-card {
width: 92%;
margin-left: 4%;
margin-right: 4%;;
background-color: white;
}
.image-wrapper {
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.image {
width: 90%;
margin-left: 5%;
margin-right: 5%;
}
I really just want to understand how overflow: auto;
was able to solve all of my problems.