OK I have looked at loads of different questions and answers on here (most flexbox questions I have found regarding aspect ratio appear to relate to using <div>
elements instead of <ul><li>
) but I cannot find the solution. When I try using <div>
tags, the images don't stay on one line. They drop down the screen, which I do not want.
I have a row of 4 images and I want them to stay in a row no matter what size screen they are viewed on, but I don't want them to cause a horizontal scroll so I am using flexbox.
However, no matter what I try, the small screen shrinks the images width correctly, but the height does not shrink accordingly, so the images are distorted.
I have tried using flex-shrink: 1;
for all items. I have tried using min-height: 0;
and min-height: 1px;
. I have also tried align-items: stretch;
but none of these makes a difference. The height still won't reduce along with the width.
here is my html code:
.flexbox-holder{
padding: 0;
margin: auto;
list-style: none;
display: flex;
flex-flow: row nowrap;
justify-content: space-between;
min-height: 1px;
}
.flexbox-item{
overflow: hidden;
flex-basis: 100%;
max-width: 240px;
min-width: 1px;
height: 100%;
max-height: 150px;
min-height: 1px;
}
<ul class="flexbox-holder">
<li class="flexbox-item"><img src="images/service1.jpg" alt="service1"></li>
<li class="flexbox-item"><img src="images/service2.jpg" alt="service1"></li>
<li class="flexbox-item"><img src="images/service3.jpg" alt="service1"></li>
<li class="flexbox-item"><img src="images/service4.jpg" alt="service1"></li>
</ul>