Skip to content

Instantly share code, notes, and snippets.

@juunegreiros
Last active March 30, 2022 21:09
Show Gist options
  • Save juunegreiros/ed695bd5d3d1c5f41b8b1b0648563a7b to your computer and use it in GitHub Desktop.
Save juunegreiros/ed695bd5d3d1c5f41b8b1b0648563a7b to your computer and use it in GitHub Desktop.
Alura Challenge 3 - dive coding
{
"categories": [
{
"id": 1,
"name": "Front-End",
"description": "HTML, CSS, React, Angular, JavaScript, jQuery e mais..."
},
{
"id": 1,
"name": "Back-End",
"description": "BE description"
},
{
"id": 1,
"name": "Data Science",
"description": "DS description"
}
]
}
:root {
--dark-blue: #071f3f;
--light-blue: #6bd1ff;
--blue: #0d4d9c;
--white: #fff;
}
* {
margin: 0;
box-sizing: border-box;
}
body {
background-color: var(--dark-blue);
}
.list {
list-style: none;
padding: 0;
display: grid;
grid-gap: 1rem;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
justify-content: space-around;
}
.card {
border: 1px solid var(--blue);
border-radius: 1rem;
display: inline-block;
padding: 1.75rem;
}
.icon {
border-radius: 4px;
width: 30px;
height: 30px;
background-color: var(--light-blue);
margin-bottom: 1rem;
}
.title {
color: var(--light-blue);
margin-bottom: 1rem;
}
.text {
color: var(--white);
}
@media (max-width: 680px) {
.text {
display: none;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="./index.css">
</head>
<body>
<ul class="list" data-list>
</ul>
<script src="./index.js"></script>
</body>
</html>
(function() {
const getCategories = async () => {
const url = 'http://localhost:3000/categories'
const data = await fetch(url)
const categories = data.json()
return categories
}
const createList = async () => {
const list = document.querySelector('[data-list]')
const categories = await getCategories()
categories.forEach((category) => {
const card = document.createElement('li')
card.classList.add('card')
card.innerHTML = `
<div class="icon"></div>
<h1 class="title">${category.name}</h1>
<p class="text">${category.description}</p>
`
list.appendChild(card)
})
}
createList()
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment