*{
    box-sizing: border-box;
}body{
    color: white;
    background-color: #222;
}
#captions_gallery {
    display: grid;
    grid-template-columns: repeat(5, auto);
    grid-auto-flow: dense;
    grid-gap: 20px;
    align-items: center;

}

#captions_gallery img {
    object-fit: contain;
    align-self: center;
    width: 100%;
    max-height: 300px;
    padding-bottom: 0.5em;
}
#captions_gallery figure{
    background-color:  white;
    margin: 0;
    padding: 1em;
    width:100%;
    height: 100%;
    display: grid;
    align-content:end;
   
}
#captions_gallery a {text-align:center;}
#captions_gallery figcaption{
    border-top: solid thin #333;
    color: #333;
    font-style: italic;
    padding-top: 0.5em;
    min-height:4em;
   
}
@media only screen and (max-width: 1400px) {
    #captions_gallery{
        grid-template-columns: repeat(4, auto);
    }  
}
@media only screen and (max-width: 800px) {
    #captions_gallery{
        grid-template-columns: repeat(3, auto);
    }
 
}
@media only screen and (max-width: 600px) {
    #captions_gallery{
        grid-template-columns: repeat(2, auto);
    }
}
@media only screen and (max-width: 400px) {
    #captions_gallery{
        grid-template-columns: auto;   
    } 
    #captions_gallery img {
        width: 90%;
        max-height: 80vh;
        justify-self:center;
    }

}