Encountering an issue with image centering in a flexbox set to direction:column
.
Imagine two elements within a flexbox, the first containing an image:
<div class="container">
<div class="image-container">
<img class="img" src="https://interactive-examples.mdn.mozilla.net/media/examples/firefox-logo.svg">
</div>
<div class="another-flex-child">
Random content here
</div>
</div>
.container {
height: 300px;
background-color: green;
display: flex;
flex-direction: column;
.image-container {
flex: 1;
align-self: center;
.img {
height: 100%;
}
}
.another-flex-child {
flex: none;
background-color: red;
}
}
Expected the image to be centered horizontally in the div, but instead, its left border aligns with the center of the div.
Replacing the image with a text-containing div shows the expected centering behavior.
Curious to understand why this discrepancy occurs.