Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sagarjadhav/50a0a2d40c05ae532b04e308102ead5c to your computer and use it in GitHub Desktop.
Save sagarjadhav/50a0a2d40c05ae532b04e308102ead5c to your computer and use it in GitHub Desktop.
Css aspect ratio to have images of same height
.img-parent img {
position: relative;
overflow: hidden;
padding-bottom: 69.44%; /* Calculated = height / width * 100 */
display: block;
}
.img-parent img {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
z-index: 0;
min-height: 100%;
width: auto;
max-width: none;
min-width: 100%;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment