.gallery {
  --s: 150px; /* control the size */
  --g: 10px;  /* control the gap */
  --f: 1.5;   /* control the scale factor */
  
  display: grid;
  gap: var(--g);
  width:  calc(var(--m)*var(--s) + (var(--m) - 1)*var(--g));
  height: calc(var(--n)*var(--s)*1.6 + (var(--n) - 1)*var(--g));
  grid-template-columns: repeat(var(--m),auto);
  
  margin-right: auto;
  margin-left: auto;
}

.gallery > img {
  width: 0;
  height: 0;
  min-height: 100%;
  min-width: 100%;
  object-fit: cover;
  cursor: pointer;
  filter: grayscale(80%);
  transition: .35s linear;
}

.gallery img:hover{
  filter: grayscale(0);
  width:  calc(var(--s)*var(--f));
  height: calc(var(--s)*var(--f));
}
  @media only screen and (max-width: 600px) {
.gallery {
  --n: 6; /* number of rows*/
  --m: 2; /* number of columns */
}
  }
  @media only screen and (min-width: 601px) {
.gallery {
  --n: 3; /* number of rows*/
  --m: 4; /* number of columns */
}
  }
