I made a website using HTML and CSS which can be seen here.
It works but as you can see, the image gallery has some spacing issues.
the first space is bigger than the other ones
As you can see, the space from the first image to the other image is inconsistent.
This is a snippet of my CSS:
.gallery {
-webkit-transition-duration: 0.25s;
transition-duration: 0.25s;
display: inline-block;
border: 3px solid #8f8f8f;
margin: 5px;
border-radius: 15px;
background-color: #29313d;
}
.gallery description {
padding: 10px;
text-align: center;
}
.gallery:hover {
border: 3px solid #ccc;
-webkit-transform: scale(1.05);
transform: scale(1.05);
}
.gallery img {
width: 200px;
height: 100px;
border-radius: 12.5px;
object-fit: cover;
}
That’s the code that causes that inconsistency. How do I fix it?
2
Answers
The space you are referring to is called margin. The images’ widths in
.gallery
are just set to200
. There is no unit here, so it is an error and is ignored in CSS by default.So, however big the images are in your gallery, the cards will just resize to that image’s default size. In this case, all
idk.png
images are 1280 x 720 pixels (This is a 16:9 ratio). The one image on the left is a different size. It is 768 x 432 pixels (This is also a 16:9 ratio).The only difference is, that in CSS, images’ margins are determined by their size. If an image is scaled down, their margins will also be scaled down. This is why the margins are smaller between all
idk.png
images. To fix this problem, simply set a specific width of all of the images (not just the "idk.png" images).I think you missing the .description class along with the width: 200 that I see you already fixed is what breaking it. You should make the following update and it should work. Add a period to the description class.