<h1>Image Gallery</h1>
<main>
<div>
<img src="" />
<h3>Title</h3>
</div>
</main>
@import url("https://fonts.googleapis.com/css2?family=Mukta&display=swap");
* {
padding: 0;
margin: 0;
box-sizing: border-box;
font-family: "Mukta", sans-serif;
}
body {
width: 100%;
min-height: 100vh;
padding: 20px;
justify-content: center;
align-items: center;
}
main {
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: center;
}
div {
padding: 20px;
margin: 20px 10px;
border: 2px solid black;
width: max(300px, 90%);
}
img {
width: 100%;
}
const main = document.querySelector("main");
async function run() {
const res = await fetch(
"https://api.airtable.com/v0/appM4Of4QQnt4Vo4Z/Table%201?maxRecords=3&view=Grid%20view",
{
headers: {
Authorization: "Bearer key6i3frJrcs78Xbq"
}
}
);
if (res.ok) {
let json = await res.json();
let html = "";
json.records.forEach((e) => {
let content = `
<div>
<img src="${e.fields.img[0].url}"/>
<h3>${e.fields.title}</h3>
</div>
`;
html += content;
});
main.innerHTML = html;
}
}
run();
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.