A unique issue arises when comparing the behavior of a simple code snippet in Chrome and Safari browsers.
Check out the HTML code below:
<div class="row">
<div class="col-md-6 d-flex">
<img class="main-img" src="http://placehold.it/2000x1000.png">
</div>
<div class="col-md-6 d-flex">
<p>Lorem<br><br><br><br><br>Ipsum</br></p>
</div>
</div>
Now, let's take a look at the accompanying CSS:
.d-flex{
background-color: #999999;
}
div > img {
margin-top: auto;
margin-bottom: auto;
width: 100%;
}
div > p {
margin-top: auto;
margin-bottom: auto;
background-color: red;
}
An interesting discrepancy is observed between Safari and Chrome regarding the space around the image. While Safari displays no additional space above or below the image, Chrome exhibits a significant gap.
It appears that Chrome calculates the image height to reserve space before adjusting the image width, whereas Safari prioritizes setting the width first before determining the height of the containing div.
So, how can we make Chrome behave more like Safari in this scenario?