I’m not as familiar with CSS grid as I probably should be since this is part of what I do for a living (probably because my day job is still stuck on Bootstrap).
However, you’ve applied a grid layout to <body>
, another to .gallery
, and you have grid CSS applied to classes like .image1
, .image2
, etc. It might be worthwhile to try removing the image classes.
Also, grid might not be the best solution for this gallery. Flexbox might be more suitable, and it’s what I’d try first. Here’s a blog post showing a few approaches to building a photo gallery using flexbox.
It might also be worthwhile to check out Solved By Flexbox for more layout ideas.
I did notice your .gallery img
rule. This won’t solve your main problem, but it should help you display photos without mangling the aspect ratio.
.gallery img {
max-width: 100%;
height: auto;
}
I also noticed that you’re not specifying widths or heights in your <img>
elements. This is necessary if you want your HTML to validate, and it also helps with lazy loading since the browser can lay out elements immediately while reserving space for images it hasn’t loaded yet.
Alt tags would be nice to have, as well, for the benefit of people using screen readers or in case an image goes missing (since your images are hosted outside Neocities).
For example, here’s one of your images.
<img class="image1"
src="https://picsum.photos/300/200?grayscale"
loading="lazy">
You would specify dimensions in the <img>
element as follows:
<img class="image1"
src="https://picsum.photos/300/200?grayscale"
width="300"
height="200"
alt="add a description here for people with poor vision"
loading="lazy">