Created
April 29, 2021 12:56
-
-
Save dm-heinze/605e722f571f43a9838d5249b816e62f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.wrapper-class { | |
display: block; | |
position: relative; | |
overflow: hidden; | |
height: 0; | |
// Give parent container a percentile padding to top, to reserve place of image. | |
// Then just position the child element (image) absolute. | |
// height px / width px * 100 = ratio in % | |
// e.g: 536 / 1024 * 100 = 52,344% | |
padding-top: 52.344%; | |
img { | |
position: absolute; | |
top: 0; | |
left: 0; | |
width: 100%; | |
height: 100%; | |
object-fit: cover; // Optional: if some images of your collection does have a different ratio | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment