I’m working on coding my graphic design portfolio website, and I’m working on creating a clickable gallery where I place images of my work in a grid. I’m able to set up the grid okay, but my pictures are all still different sizes and its messing up the grid.
the grid I’m working on looks like this:
It is my first time posting, I’m sorry if this isn’t explained well.
.gallery {
width: 700px;
display: flex;
}
.gallery div {
width: 100%;
display: grid;
grid-template-columns: auto auto auto;
grid-gap: 20px;
padding: 10px;
flex: none;
}
.gallery div img {
width: 400px;
background-size: cover;
}
<div class="gallery">
<div>
<span><img src="images/cafe ole final-01 copy.png" alt="Cafe Ole"></span>
<span><img src="images/Nintendo logo redesign-03.png" alt="Nintendo redesign"></span>
<span><img src="images/shibuya airport logo branding-02 copy.png" alt="Shibuya Airport"></span>
<span><img src="images/rocket wireless.png" alt="rocket wireless"></span>
<span><img src="images/transfriend logo 2-02.png" alt="transfriend"></span>
<span><img src="images/Spotify UI Design.png" alt="Spotify UI Design"></span>
<span><img src="images/bapeshoead2-01 copy.png" alt=""></span>
</div>
</div>
3
Answers
Try this out. Instead of an
<img>
tag just set thebackground-image
style on each element and then you have full control in CSS of how it appears. If you usebackground-size: cover;
it is cropped to a square in the middle of each image. If you instead usebackground-size: contain;
you see the full image but it might have some empty space around it. It just depends what you want to do.If you want your pictures are same sizes and it should not messing up the grid then you should try them with proper height and width and still if you seeing same issue try object-fit property.
Try This;
I wrapped each img with "a" tag for make them clickable. And target="_blank" is for the new tab but you can remove all if u want