I want to make a 3x3 grid(the cells are images), using "grid" in css, with this:
- Each cell of the grid is a square
- The grid is responsive(I don't want something like
display:flex; flex-wrap: wrap
) I mean when the screen become smaller the cells of the grid are still squares and the grid take 100% width
Other thing that I don't know how to solve is:
- In the cells of the grid, put images(the ratio is not like a square), but the images maintain their ratio, I mean like crop a image
What I've tried: I've make the html sintax:
<div class="grid">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/4/41/Istanbul_Skyline_Be%C5%9Fikta%C5%9F_%C5%9Ei%C5%9Fli.JPG/750px-Istanbul_Skyline_Be%C5%9Fikta%C5%9F_%C5%9Ei%C5%9Fli.JPG">
<img src="https://www.turismoviajar.com/wp-content/uploads/2019/10/paris-2020.jpg">
<img src="https://ice-2020.com/wp-content/uploads/2018/11/GettyImages-674739845-1200x800.jpg">
<img src="https://eufcn.com/wp-content/uploads/2017/11/madrid_filmmadrid.jpg">
<img src="https://www.futbolred.com/files/article_main/uploads/2020/05/29/5ed193de4ae3f.jpeg">
<img src="https://lp-cms-production.imgix.net/2019-06/GettyImages-538096543_medium.jpg?fit=crop&q=40&sharp=10&vib=20&auto=format&ixlib=react-8.6.4">
<img src="https://blog.global-exchange.com/wp-content/uploads/2018/08/Moscu-calles-840.jpg">
<img src="https://www.turismoviajar.com/wp-content/uploads/2019/10/Rio-de-Janeiro-2020.jpg">
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcQj3iLwvZZO-JzJAPquVMTORT4CPOFURK6fzA&usqp=CAU">
</div>
and the css is
.grid{
display: grid;
width: 100%;
grid-template-columns: auto auto auto;
height: auto;
/*This doesn't work, the height is fit to the images*/
grid-template-rows: auto auto auto;
/* This doesn't work, the cells are not squares*/
}
.grid > img{
width: 100%;
height: 100%;
/*In this way I lose the ratio of the image*/
}