<!-- LQIP example with TwicPics (http://www.twicpics.com) -->
<main>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-artichoke.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-artichoke.jpg" alt="Artichoke">
<figcaption>Artichoke</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-canyon.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-canyon.jpg" alt="Canyon">
<figcaption>Canyon</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-friend.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-friend.jpg" alt="Friend">
<figcaption>Friend</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-cereals.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-cereals.jpg" alt="Cereals">
<figcaption>Ceretwicals</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-lion.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-lion.jpg" alt="Lion">
<figcaption>Lion</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-doggy.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-doggy.jpg" alt="Doggy">
<figcaption>Doggy</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-cafe.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-cafe.jpg" alt="Cafe">
<figcaption>Cafe</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-castle.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-castle.jpg" alt="Castle">
<figcaption>Castle</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-lake.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-lake.jpg" alt="Lake">
<figcaption>Lake</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-rasp.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-rasp.jpg" alt="Rasp">
<figcaption>Rasp</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-moth.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-moth.jpg" alt="Moth">
<figcaption>Moth</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-pug.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-pug.jpg" alt="Pug">
<figcaption>Pug</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-artichoke.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-artichoke.jpg" alt="Artichoke">
<figcaption>Artichoke</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-canyon.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-canyon.jpg" alt="Canyon">
<figcaption>Canyon</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-friend.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-friend.jpg" alt="Friend">
<figcaption>Friend</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-cereals.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-cereals.jpg" alt="Cereals">
<figcaption>Ceretwicals</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-lion.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-lion.jpg" alt="Lion">
<figcaption>Lion</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-doggy.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-doggy.jpg" alt="Doggy">
<figcaption>Doggy</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-cafe.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-cafe.jpg" alt="Cafe">
<figcaption>Cafe</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-castle.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-castle.jpg" alt="Castle">
<figcaption>Castle</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-lake.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-lake.jpg" alt="Lake">
<figcaption>Lake</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-rasp.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-rasp.jpg" alt="Rasp">
<figcaption>Rasp</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-moth.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-moth.jpg" alt="Moth">
<figcaption>Moth</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-pug.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-pug.jpg" alt="Pug">
<figcaption>Pug</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-artichoke.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-artichoke.jpg" alt="Artichoke">
<figcaption>Artichoke</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-canyon.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-canyon.jpg" alt="Canyon">
<figcaption>Canyon</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-friend.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-friend.jpg" alt="Friend">
<figcaption>Friend</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-cereals.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-cereals.jpg" alt="Cereals">
<figcaption>Ceretwicals</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-lion.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-lion.jpg" alt="Lion">
<figcaption>Lion</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-doggy.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-doggy.jpg" alt="Doggy">
<figcaption>Doggy</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-cafe.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-cafe.jpg" alt="Cafe">
<figcaption>Cafe</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-castle.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-castle.jpg" alt="Castle">
<figcaption>Castle</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-lake.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-lake.jpg" alt="Lake">
<figcaption>Lake</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-rasp.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-rasp.jpg" alt="Rasp">
<figcaption>Rasp</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-moth.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-moth.jpg" alt="Moth">
<figcaption>Moth</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-pug.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-pug.jpg" alt="Pug">
<figcaption>Pug</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-artichoke.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-artichoke.jpg" alt="Artichoke">
<figcaption>Artichoke</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-canyon.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-canyon.jpg" alt="Canyon">
<figcaption>Canyon</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-friend.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-friend.jpg" alt="Friend">
<figcaption>Friend</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-cereals.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-cereals.jpg" alt="Cereals">
<figcaption>Ceretwicals</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-lion.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-lion.jpg" alt="Lion">
<figcaption>Lion</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-doggy.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-doggy.jpg" alt="Doggy">
<figcaption>Doggy</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-cafe.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-cafe.jpg" alt="Cafe">
<figcaption>Cafe</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-castle.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-castle.jpg" alt="Castle">
<figcaption>Castle</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-lake.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-lake.jpg" alt="Lake">
<figcaption>Lake</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-rasp.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-rasp.jpg" alt="Rasp">
<figcaption>Rasp</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-moth.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-moth.jpg" alt="Moth">
<figcaption>Moth</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-pug.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-pug.jpg" alt="Pug">
<figcaption>Pug</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-artichoke.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-artichoke.jpg" alt="Artichoke">
<figcaption>Artichoke</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-canyon.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-canyon.jpg" alt="Canyon">
<figcaption>Canyon</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-friend.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-friend.jpg" alt="Friend">
<figcaption>Friend</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-cereals.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-cereals.jpg" alt="Cereals">
<figcaption>Ceretwicals</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-lion.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-lion.jpg" alt="Lion">
<figcaption>Lion</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-doggy.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-doggy.jpg" alt="Doggy">
<figcaption>Doggy</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-cafe.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-cafe.jpg" alt="Cafe">
<figcaption>Cafe</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-castle.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-castle.jpg" alt="Castle">
<figcaption>Castle</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-lake.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-lake.jpg" alt="Lake">
<figcaption>Lake</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-rasp.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-rasp.jpg" alt="Rasp">
<figcaption>Rasp</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-moth.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-moth.jpg" alt="Moth">
<figcaption>Moth</figcaption>
</figure>
<figure style="background-image: url(https://demo.twic.pics/codepen/tp-pug.jpg?twic=v1/output=preview)">
<img data-twic-src="image:codepen/tp-pug.jpg" alt="Pug">
<figcaption>Pug</figcaption>
</figure>
</main>
$breakpoint-from-tablet: "only screen and (min-width: 768px)";
$breakpoint-from-desktop-sml: "only screen and (min-width: 769px)";
$breakpoint-from-desktop-mid: "only screen and (min-width: 1200px)";
$breakpoint-from-desktop-lrg: "only screen and (min-width: 1600px)";
@mixin aspect-ratio($width, $height) {
position: relative;
overflow: hidden;
&:before {
display: block;
content: "";
width: 100%;
padding-top: ($height / $width) * 100%;
}
> img {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
}
html {
box-sizing: border-box;
}
*,
*:before,
*:after {
box-sizing: inherit;
}
main {
padding: 10px;
@media #{ $breakpoint-from-tablet } {
display: flex;
justify-content: space-around;
flex-direction: row;
flex-wrap: wrap;
}
}
figure {
@include aspect-ratio(16, 9);
background-color: white;
background-position: center;
background-size: cover;
background-repeat: no-repeat;
border: 10px solid white;
margin: auto;
width: 100%;
@media #{ $breakpoint-from-tablet } {
@include aspect-ratio(1, 1);
flex: 0 1 auto;
width: 50%;
}
@media #{ $breakpoint-from-desktop-sml } {
width: 33%;
}
@media #{ $breakpoint-from-desktop-mid } {
@include aspect-ratio(4, 3);
width: 33%;
}
@media #{ $breakpoint-from-desktop-lrg } {
@include aspect-ratio(4, 3);
width: 25%;
}
img {
display: block;
object-fit: cover;
width: 100%;
height: 100%;
opacity: 0;
transform: scale(1);
will-change: opacity, transform;
transition: opacity 1s linear, transform .75s ease-out;
&.twic-done {
opacity: 1;
}
&:hover {
transform: scale(1.1);
}
}
figcaption {
position: absolute;
bottom: 0;
width: 100%;
background-color: rgba(black, 0.5);
padding: 8px 10px;
font-size: 12px;
color: white;
text-transform: uppercase;
}
}
View Compiled
This Pen doesn't use any external CSS resources.