I am trying to reproduce this image and unfortunately, after hours of trying with display flex, i do not succeed. They either get stuck in column and do not move or they stay in row without divide in 2. I want 5 images on top and 4 bellow. All of the images needs to be in the same container
.
Here the result of what i tried…. even with flex wrap, it seems to not move a lot.
.container2 {
display: flex;
flex-wrap: wrap;
}
<main>
<section>
<div>
<h2>PHOTOS TROP MIGNONNES DE CHATS</h2>
</div>
<div class="container2">
<img class="chatprincipal chathaut" src="https://placekitten.com/200/300">
<img class="chatprincipal chathaut" src="https://placekitten.com/240/300">
<img class="chatprincipal chathaut" src="https://placekitten.com/100/200">
<img class="chatprincipal chathaut" src="https://placekitten.com/200/200">
<img class="chatprincipal chathaut" src="https://placekitten.com/110/330">
<img class="chatprincipal chathaut" src="https://placekitten.com/120/250">
<img class="chatprincipal chathaut" src="https://placekitten.com/220/300">
<img class="chatprincipal chathaut" src="https://placekitten.com/130/300">
<img class="chatprincipal chathaut" src="https://placekitten.com/140/300">
</div>
</section>
</main>
2
Answers
Flex is the right approach. The key is to style your images with a
width
of 18%; so five images will take up 90% of the available width, and the remaining images will wrap to the next line. Add the stylejustify-content: space-around
to space the images evenly along the lines.After running this snippet, use the full page link to properly test the responsive behaviour.
Could you try this code? And what’s the max width of the body or the flex-container?