I'm trying to display images in a container, but i have a problem when resizing the browser window: Before going from 6 to 4 items, it stays at 6 items per row, but now they overlap
Here is what i'm talking about: https://www.bootply.com/render/dKyKQWIL9j
The images have to stay a fixed size (160x230) and there should always be a margin of 7 at top/bottom and some margin inbetween the items in a row (just not a margin on the outer left and right, so the images allign perfectly in the container)
Here is my code:
<div class="container" style="border:1px solid green">
<div class="row">
<div class="col-6 col-sm-4 col-md-3 col-lg-2" style="margin-top:7px;margin-bottom:7px;border:1px solid red">
<a href="#" class="d-block mb-6">
<img class="rounded img-fluid" src="http://via.placeholder.com/160x230.jpg" width="160" height="230">
</a>
</div>
<div class="col-6 col-sm-4 col-md-3 col-lg-2" style="margin-top:7px;margin-bottom:7px;border:1px solid red">
<a href="#" class="d-block mb-6">
<img class="rounded img-fluid" src="http://via.placeholder.com/160x230.jpg" width="160" height="230">
</a>
</div>
<div class="col-6 col-sm-4 col-md-3 col-lg-2" style="margin-top:7px;margin-bottom:7px;border:1px solid red">
<a href="#" class="d-block mb-6">
<img class="rounded img-fluid" src="http://via.placeholder.com/160x230.jpg" width="160" height="230">
</a>
</div>
<div class="col-6 col-sm-4 col-md-3 col-lg-2" style="margin-top:7px;margin-bottom:7px;border:1px solid red">
<a href="#" class="d-block mb-6">
<img class="rounded img-fluid" src="http://via.placeholder.com/160x230.jpg" width="160" height="230">
</a>
</div>
<div class="col-6 col-sm-4 col-md-3 col-lg-2" style="margin-top:7px;margin-bottom:7px;border:1px solid red">
<a href="#" class="d-block mb-6">
<img class="rounded img-fluid" src="http://via.placeholder.com/160x230.jpg" width="160" height="230">
</a>
</div>
<div class="col-6 col-sm-4 col-md-3 col-lg-2" style="margin-top:7px;margin-bottom:7px;border:1px solid red">
<a href="#" class="d-block mb-6">
<img class="rounded img-fluid" src="http://via.placeholder.com/160x230.jpg" width="160" height="230">
</a>
</div>
<div class="col-6 col-sm-4 col-md-3 col-lg-2" style="margin-top:7px;margin-bottom:7px;border:1px solid red">
<a href="#" class="d-block mb-6">
<img class="rounded img-fluid" src="http://via.placeholder.com/160x230.jpg" width="160" height="230">
</a>
</div>
<div class="col-6 col-sm-4 col-md-3 col-lg-2" style="margin-top:7px;margin-bottom:7px;border:1px solid red">
<a href="#" class="d-block mb-6">
<img class="rounded img-fluid" src="http://via.placeholder.com/160x230.jpg" width="160" height="230">
</a>
</div>
<!-- etc... -->
</div>
</div>
(The solid borders are just there for testing)
Any help is greatly appreciated. I'm kind of new to css and html, but i did my best reading the bootstrap documentation of their grid system, but i couldn't find anything in between col-6 col-sm-4 col-md-3 col-lg-2
to fix my problem. Thanks in advance!
Edit:
When resizing the browser window the images should always stay the same resolution and go from 6 items in a row down to 2 items per row (so 6-5-4-3-2), while always filling the screen as soon as the browser size is smaller than the container.