A Pen by Jens Grochtdreis on CodePen.
Created
June 15, 2023 13:56
-
-
Save jensgro/c8619b58f386064cfe79ed23b7019c5d to your computer and use it in GitHub Desktop.
Responsive Image with srcset
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
<h1>Responsive Images with srcset</h1> | |
<div class="wrapper"> | |
<img class="flexible" | |
srcset="https://via.placeholder.com/320x160/ddd 320w, | |
https://via.placeholder.com/480x240/ccc 480w, | |
https://via.placeholder.com/768x384/444/fff 768w, | |
https://via.placeholder.com/1024x512/a20000/fff 1024w, | |
https://via.placeholder.com/1280x640/fd8700/000 1280w" | |
sizes="(max-width: 20em) 100vw, | |
(max-width: 30em) 60vw, | |
(max-width: 40em) 50vw" | |
src="https://via.placeholder.com/400x200&text=Fallback" | |
alt="" /> | |
</div> |
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 { | |
width: 94%; | |
margin: 20px auto; | |
padding: 10px; | |
background-color: #fff; | |
} | |
body { | |
background-color: #ccc; | |
} | |
.flexible { | |
width: auto; | |
height: auto; | |
max-width: 100%; | |
} | |
h1 {text-align: center;} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment