I have images within a container element. When the image height is less than the container height I want the image at the top of the container. When the image width is less than the container width I want the image centered.
This is how I want it to look and it works on desktop Firefox and Chrome.
However, on desktop Safari and mobile Safari, Firefox and Chrome it looks like this with the shorter image centered vertically and the narrower width image stretched to fit the container width:
#container {
display: flex;
flex-direction: row;
}
.mainImageContainer {
width: 500px;
height: 375px;
margin: 1rem;
}
.mainImageBtn {
background-color: rgb(231, 60, 60);
display: -webkit-box; /* tried this did not work */
display: -webkit-flex; /* tried this did not work */
display: -moz-box; /* tried this did not work */
display: -ms-flexbox; /* tried this did not work */
display: flex;
width: 500px;
height: 375px;
border: none;
padding: 0;
justify-content: center;
-webkit-box-pack: start; /* tried this did not work */
-webkit-box-align: start; /* tried this did not work */
-webkit-flex-align: start; /* tried this did not work */
-ms-flex-align: start; /* tried this did not work */
-webkit-align-items: start; /* tried this did not work */
align-items: flex-start;
}
.mainImage {
cursor: zoom-in;
max-width: 100%;
max-height: 100%;
}
<div id="container">
<div class="mainImageContainer">
<button class="mainImageBtn">
<img class="mainImage" src="https://eoja82.github.io/For-Sale/img/car_2.jpg" alt="car"></img>
</button>
</div>
<div class="mainImageContainer">
<button class="mainImageBtn">
<img class="mainImage" src="https://eoja82.github.io/For-Sale/img/tumbler%20-%202.jpeg" alt="instructions"></img>
</button>
</div>
</div>
I read this but none of the solutions worked for me: How do I make flex box work in safari?.
I'm using the latest versions of the browsers.