I want to make a grid of photos 5x2, which corresponds to the designer's plan. If all the pictures are present, then it is not difficult to implement exactly and as it should, but if the grid collapses for one reason or another (5 pictures do not fit into the line, there are not enough pictures per line out of 5), then difficulties arise. The difficulty is that the first and last picture in the line should rest on the border of the container (.wrapper), thus it is impossible to simply take and use for example the pseudo-class: first-of-type and similar to just remove the extra indent from the last element.
HTML:
<section class="portfolio"> <div class="wrapper"> <ul class="gallery"> <li> </li> <li> </li> <li> </li> <li> </li> <li> </li> <li> </li> <li> </li> <li> </li> <li> </li> <li> </li> </ul> </div> </section> CSS:
* { box-sizing: border-box; padding: 0; margin: 0; } .wrapper { margin-right: 140px; margin-left: 140px; } .portfolio .gallery{ list-style-type: none; height: 550px; text-align:center; } .portfolio .gallery > li{ margin-right: 50px; margin-bottom: 50px; width: 280px; height: 250px; background-color: grey; display: inline-block; } /* Обнуление отступа у каждого крайнего элемента*/ /* Ломается при недостаче элементов */ .portfolio .gallery li:nth-of-type(5n) { margin-right: 0; } How to be?