I was completely tortured with math, I'm already starting to just guess. (You need to make a gallery, like masonry or justifeid, only without js, and horizontal.

You can calc, you can flex, you can custom-properties, you can not grid.

This is what happened (do not pay attention to the quality of the code, the main thing is to make it work, then we will comb it):

.pic-flex { --var-m: 8; display: flex; } .pic-flex div { --var-r: calc(1vw * var(--var-a) / 150); box-sizing: border-box; background-repeat: no-repeat; background-size: contain; padding-left: calc(var(--var-w) / var(--var-h) * var(--var-r)); height: var(--var-r); } .pic-flex div:not(:last-child) { margin-right: calc(var(--var-m) * 1px); margin-bottom: calc(var(--var-m) * 1px); } 
 <div class="pic-flex" style="--var-a: calc(1200 + 800 + 800 + 2 * var(--var-m));"> <div style="--var-w: 1200; --var-h: 768; background-image: url(//placehold.it/1200x768);"></div> <div style="--var-w: 800; --var-h: 600; background-image: url(//placehold.it/800x600);"></div> <div style="--var-w: 800; --var-h: 600; background-image: url(//placehold.it/800x600);"></div> </div> <div class="pic-flex" style="--var-a: calc(800 + 1360 + 800 + 2 * var(--var-m));"> <div style="--var-w: 800; --var-h: 600; background-image: url(//placehold.it/800x600);"></div> <div style="--var-w: 1360; --var-h: 768; background-image: url(//placehold.it/1360x768);"></div> <div style="--var-w: 800; --var-h: 600;; background-image: url(//placehold.it/800x600);"></div> </div> <div class="pic-flex" style="--var-a: calc(1366 + 1920 + 1 * var(--var-m));"> <div style="--var-w: 1366; --var-h: 776;; background-image: url(//placehold.it/1366x776);"></div> <div style="--var-w: 1920; --var-h: 768; background-image: url(//placehold.it/1920x768);"></div> </div> 

It is necessary that this is the case (the aspect of the images should be normal by itself): enter image description here

    2 answers 2

    Damn, it seems to work! )))

    UPDATE: A non-universal solution, with images of equal width but different heights, works crookedly.

     .pic-flex { --var-m: 8; display: flex; } .pic-flex div { --var-r: 18vw; background-repeat: no-repeat; background-size: cover; background-position: center center; height: var(--var-r); flex-basis: calc(100% / var(--var-a) * var(--var-w)); } .pic-flex div:not(:last-child) { margin-right: calc(var(--var-m) * 1px); margin-bottom: calc(var(--var-m) * 1px); } @media (max-width: 700px) { .pic-flex { --var-m: 4; } } 
     <div class="pic-flex" style="--var-a: calc(1200 + 800 + 800);"> <div style="--var-w: 1200; --var-h: 768; background-image: url(//placehold.it/1200x768);"></div> <div style="--var-w: 800; --var-h: 600; background-image: url(//placehold.it/800x600);"></div> <div style="--var-w: 800; --var-h: 600; background-image: url(//placehold.it/800x600);"></div> </div> <div class="pic-flex" style="--var-a: calc(800 + 1360 + 800);"> <div style="--var-w: 800; --var-h: 600; background-image: url(//placehold.it/800x600);"></div> <div style="--var-w: 1360; --var-h: 768; background-image: url(//placehold.it/1360x768);"></div> <div style="--var-w: 800; --var-h: 600;; background-image: url(//placehold.it/800x600);"></div> </div> <div class="pic-flex" style="--var-a: calc(1366 + 1920);"> <div style="--var-w: 1366; --var-h: 776;; background-image: url(//placehold.it/1366x776);"></div> <div style="--var-w: 1920; --var-h: 768; background-image: url(//placehold.it/1920x768);"></div> </div> 

      I came up with another option, he is fine with both portrait and landscape images.

       .pic-flex { --var-m: 8; display: flex; } .pic-flex div { --var-r: 20vw; background-repeat: no-repeat; background-size: cover; background-position: center center; height: var(--var-r); flex: calc(var(--var-w) / var(--var-h)) 1 auto; } .pic-flex div:not(:last-child) { margin-right: calc(var(--var-m) * 1px); margin-bottom: calc(var(--var-m) * 1px); } @media (max-width: 700px) { .pic-flex { --var-m: 4; } } 
       <div class="pic-flex"> <div style="--var-w: 1200; --var-h: 768; background-image: url(//placehold.it/1200x768);"></div> <div style="--var-w: 800; --var-h: 600; background-image: url(//placehold.it/800x600);"></div> <div style="--var-w: 800; --var-h: 600; background-image: url(//placehold.it/800x600);"></div> </div> <div class="pic-flex"> <div style="--var-w: 775; --var-h: 477;; background-image: url(//placehold.it/775x477);"></div> <div style="--var-w: 775; --var-h: 1163; background-image: url(//placehold.it/775x1163);"></div> <div style="--var-w: 775; --var-h: 1089; background-image: url(//placehold.it/775x1089);"></div> </div> <div class="pic-flex"> <div style="--var-w: 1366; --var-h: 776;; background-image: url(//placehold.it/1366x776);"></div> <div style="--var-w: 1920; --var-h: 768; background-image: url(//placehold.it/1920x768);"></div> </div>