Skip to content

Instantly share code, notes, and snippets.

@mrtag23
Last active August 2, 2019 23:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrtag23/9343b10cb35f1f8a4c82e96c8b60a5a0 to your computer and use it in GitHub Desktop.
Save mrtag23/9343b10cb35f1f8a4c82e96c8b60a5a0 to your computer and use it in GitHub Desktop.
Simple picture component for pattern lab.
{
"breakpoints": {
"desktop": "all and (min-width: 1200px)",
"tablet": "all and (min-width: 768px) and (max-width: 1199px)",
"mobile": "all and (max-width: 767px)"
}
}
<picture>
{% for key, source in sources %}
<source media="{{ breakpoints[key] }}" srcset="{{ source }}">
{% endfor %}
<img src="{{ src }}" alt="{{ alt }}">
</picture>
sources:
desktop: "https://via.placeholder.com/1920x1080?text=Desktop+image"
tablet: "https://via.placeholder.com/1200x900?text=Tablet+image"
mobile: "https://via.placeholder.com/768x500?text=Mobile+image"
src: "https://via.placeholder.com/1920x1080?text=Fallback+image"
alt: "Vestibulum ante ipsum"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment