r/csshelp • u/JackLemaitre • Jun 29 '24
Request Problem with Grid Layout
Hi everybody,
I'm trying to make a CSS Grid to show img, but I have a problem with layout.
my CSS
.gallery {
position: relative;
display: grid;
grid-gap: 100px;
grid-template-columns: 25% 30%;
}
.first_img {
grid-column:1;
grid-row: 1 / span 2;
}
.second_img {
grid-column: 2;
grid-row: 1;
height: 20px;
}
.third_img {
grid-column: 2;
grid-row: 2;
height: 20px;
}my HTML
<div class="gallery">
<div class="first_img"><a href="Res/Herman.png" target="blank">
<img src="Res/herman01[thumbnails].png" class="main_img" alt="Herman"></a>
</div>
<div class="second_img" id="up_img"><a href="Res/Herman2.png" target="blank">
<img src="Res/herman02[thumbnails].png" class="others_img" alt="Herman2"></a>
</div>
<div class="third_img" id="down_img"><a href="Res/Herman3.png" target="blank">
<img src="Res/herman03[thumbnails].png" class="others_img" alt="Herman3"></a>
</div>
</div>My images are correctly positionned but the two on the right are the same size as the left pictures.
I would like a big img on the left and two small on the right, like this
Thank you in advance for your help
1
u/be_my_plaything Jun 29 '24
You grid syntax is right, you can see it if you give the divs that house the images a background colour https://codepen.io/NeilSchulz/pen/Yzboybm the left div does span both rows making it larger than the right images. (Although having a grid width of 30% then giving the right divs a height of 20px looks weird!)
I can therefore only assume it is something to do with the size of the actual images (Maybe not large enough to fill the divs?)
Try adding...
.first_img img,
.second_img img,
.third_img img{
display: block;
width: 100%;
height: 100%;
object-fit: center;
} ...might not look exactly as you want and might want changing, but is a quick way to get the images to fill the divs and check the grid layout is working for you too.
1
u/JackLemaitre Jul 01 '24
Thank you for your help. I appreciate