Stay organized with collections
Save and categorize content based on your preferences.
HTML
<div class="grid">
<div class="item">
<div class="image-container">
<img src="hats.jpg">
</div>
<div class="text-container">Hats</div>
</div>
<div class="item empty">
<div class="image-container">
<img src="">
</div>
<div class="text-container">Watches</div>
</div>
<div class="item empty">
<div class="image-container">
<img src="">
</div>
<div class="text-container"></div>
</div>
<div class="item empty">
<div class="image-container">
<img src="">
</div>
<div class="text-container"></div>
</div>
<div class="item empty">
<div class="image-container">
<img src="">
</div>
<div class="text-container"></div>
</div>
<div class="item empty">
<div class="image-container">
<img src="">
</div>
<div class="text-container"></div>
</div>
</div>
CSS
:root {
--placeholder-primary: #eeeeee;
--placeholder-secondary: #cccccc;
}
.grid {
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: center;
gap: 1em;
width: 100%;
max-width: 650px;
margin: 1em 0;
}
.item {
display: grid;
gap: .5em;
width: 200px;
}
.text-container {
font-size: 1em;
height: 1.5em;
text-align: center;
font-weight: bold;
}
.image-container {
width: 200px;
height: 200px;;
animation: placeholder ease-in-out 2s infinite;
}
.image-container img {
width: 100%;
}
@keyframes placeholder {
0% {
background-color: var(--placeholder-primary);
}
50% {
background-color: var(--placeholder-secondary);
}
100% {
background-color: var(--placeholder-primary);
}
}
@keyframes fadeIn {
0% {
opacity: 0%;
}
100% {
opacity: 100%;
}
}
.item.loaded .image-container {
animation: none;
}
.item.loaded .image-container img{
animation: fadeIn linear .5s;
}
JS
const data = [
{
description: "Watches",
src: "watches.jpg"
},
{
description: "Shirt",
src: "shirt.jpg"
},
{
description: "Shorts",
src: "shorts.jpg"
},
{
description: "Sunglasses",
src: "sunglasses.jpg"
},
{
description: "Shoes",
src: "shoes.jpg"
}
];
document.querySelectorAll(".item.empty").forEach((el, index) => {
if (data[index]) {
el.classList = "item loaded";
el.querySelector("img").src = data[index].src;
el.querySelector(".text-container").innerHTML = data[index].description;
}
});
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-01-16 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-01-16 UTC."],[],[]]