First, let's get rid of some properties to have the following:
.footer {
font-size: 15px;
line-height: 1.2em;
width: 100vw;
background-color: #090B19;
color: white;
}
.footer .icons {
display: grid;
grid-template-columns: repeat(3, 1fr);
/* grid-template-rows: 100%;*/
margin: 0 auto;
}
img {
/* height: 100%; */
width: 100%;
outline:1px solid red;
}
<div class="footer">
<div class="icons">
<a href="www.google.com" target="_blank"><img src="https://www.applesfromny.com/wp-content/uploads/2020/05/Jonagold_NYAS-Apples2.png" class="github-img"></a>
<a href="https://stackoverflow.com/users/14037283/tonitone120?tab=summary" target="_blank"><img src="https://www.applesfromny.com/wp-content/uploads/2020/05/Jonagold_NYAS-Apples2.png" class="so-image"></a>
<a href="www.google.com" target="_blank"><img src="https://media.istockphoto.com/photos/whole-kiwi-fruit-and-half-kiwi-fruit-on-white-picture-id834807852?k=6&m=834807852&s=612x612&w=0&h=qyouQR9CrIlrPo8FG72PCt1eBV_lTVtnuwVlo9hWZY8=" class="linked-image"></a>
</div>
</div>
You have a footer with a width equal to 100vw
divided into 3 equal columns (so around 33.33vw
each). Each image will be width:100%
inside each column and they will keep their ratio. Logically this will define the height of the footer and the height of the single row. Since we are dealing with CSS grid, all the columns inside the same row will have equal height and this height is the key here and the one used as a reference when adding height:100%
to the images:
.footer {
font-size: 15px;
line-height: 1.2em;
width: 100vw;
background-color: #090B19;
color: white;
}
.footer .icons {
display: grid;
grid-template-columns: repeat(3, 1fr);
/* grid-template-rows: 100%;*/
margin: 0 auto;
}
img {
height: 100%;
width: 100%;
outline:1px solid red;
}
<div class="footer">
<div class="icons">
<a href="www.google.com" target="_blank"><img src="https://www.applesfromny.com/wp-content/uploads/2020/05/Jonagold_NYAS-Apples2.png" class="github-img"></a>
<a href="https://stackoverflow.com/users/14037283/tonitone120?tab=summary" target="_blank"><img src="https://www.applesfromny.com/wp-content/uploads/2020/05/Jonagold_NYAS-Apples2.png" class="so-image"></a>
<a href="www.google.com" target="_blank"><img src="https://media.istockphoto.com/photos/whole-kiwi-fruit-and-half-kiwi-fruit-on-white-picture-id834807852?k=6&m=834807852&s=612x612&w=0&h=qyouQR9CrIlrPo8FG72PCt1eBV_lTVtnuwVlo9hWZY8=" class="linked-image"></a>
</div>
</div>
In other words, the content was used to define the height of our column and this height was later considered as reference of our percentage height. Note that grid-template-rows: 100%
is useless here and will do nothing since we have no reference to resolve that percentage. It will only have an effect in case you define an explicit height on the grid:
.footer {
font-size: 15px;
line-height: 1.2em;
width: 100vw;
background-color: #090B19;
color: white;
}
.footer .icons {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: 100%;
margin: 0 auto;
height: 200px;
}
img {
height: 100%;
width: 100%;
outline:1px solid red;
}
<div class="footer">
<div class="icons">
<a href="www.google.com" target="_blank"><img src="https://www.applesfromny.com/wp-content/uploads/2020/05/Jonagold_NYAS-Apples2.png" class="github-img"></a>
<a href="https://stackoverflow.com/users/14037283/tonitone120?tab=summary" target="_blank"><img src="https://www.applesfromny.com/wp-content/uploads/2020/05/Jonagold_NYAS-Apples2.png" class="so-image"></a>
<a href="www.google.com" target="_blank"><img src="https://media.istockphoto.com/photos/whole-kiwi-fruit-and-half-kiwi-fruit-on-white-picture-id834807852?k=6&m=834807852&s=612x612&w=0&h=qyouQR9CrIlrPo8FG72PCt1eBV_lTVtnuwVlo9hWZY8=" class="linked-image"></a>
</div>
</div>
Resize the screen of the above example and you will notice that the height of the grid, the row and the 3 columns will be equal to 200px
because we explicitely defined that height unlike the first case where it was defined by the content.
Another non intuitive example where we will have one image that will define the height and will have its height as percentage based on its own height!
.icons {
display: grid;
margin: 0 auto;
width:80%;
border:2px solid
}
img {
height: 150%;
display:block;
width: 100%;
outline: 1px solid red;
}
<div class="icons">
<a href="www.google.com" target="_blank"><img src="https://www.applesfromny.com/wp-content/uploads/2020/05/Jonagold_NYAS-Apples2.png" class="github-img"></a>
</div>
Note how the image will overflow by exaclty 50%
which is the difference between 150%
and 100%
where 100%
is the height of the image if we set no height.
Related question with similar examples: Why is my Grid element's height not being calculated correctly?