Created
July 23, 2026 14:18
-
-
Save aFarkas/d78b5f85ddf79f1d46e6481805554692 to your computer and use it in GitHub Desktop.
sizes=auto for height/object-fit determined images.
This file contains hidden or 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
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <title>Title</title> | |
| </head> | |
| <body> | |
| <style> | |
| .group { | |
| display: flex; | |
| align-items: stretch; | |
| } | |
| .card { | |
| position: relative; | |
| min-height: 100px; | |
| width: 200px; | |
| border: 1px solid black; | |
| padding: 10px; | |
| margin: 10px; | |
| overflow: hidden; | |
| } | |
| .big { | |
| height: 400px; | |
| } | |
| .object-fit-box { | |
| position: absolute; | |
| inset: 0; | |
| display: grid; | |
| place-items: center; | |
| overflow: hidden; | |
| } | |
| .object-fit-box img { | |
| grid-area: 1 / 1; | |
| width: auto; | |
| height: auto; | |
| max-width: none; | |
| min-width: 100%; | |
| min-height: 100%; | |
| } | |
| </style> | |
| <div class="group"> | |
| <div class="card"> | |
| content small has min-height | |
| </div> | |
| <div class="card"> | |
| <div class="object-fit-box"> | |
| <img | |
| srcset="https://placehold.co/600x400 600w, | |
| https://placehold.co/1200x800 1200w," | |
| width="600" height="400" | |
| loading="lazy" | |
| sizes="auto, 1200px" /> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="group"> | |
| <div class="card"> | |
| <div class="big"> | |
| content big stretches items | |
| </div> | |
| </div> | |
| <div class="card"> | |
| <div class="object-fit-box"> | |
| <img | |
| srcset="https://placehold.co/600x400/orange/white 600w, | |
| https://placehold.co/1200x800/orange/white 1200w," | |
| width="600" height="400" | |
| loading="lazy" | |
| sizes="auto, 1200px" /> | |
| </div> | |
| </div> | |
| </div> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment