Accordions 01
const cardsContainer = document.querySelector(".container");
cardsContainer.addEventListener("click", (e) => {
const target = e.target.closest(".card");
if (!target) return;
cardsContainer.querySelectorAll(".card").forEach((card) => {
card.classList.remove("active");
});
target.classList.add("active");
});
@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500&display=swap");
*,
*::before,
*::after {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: Inter, sans-serif;
height: 100vh;
color: white;
background-color: #e9e9f0;
display: flex;
justify-content: center;
align-items: center;
}
img {
width: 100%;
height: 100%;
display: block;
}
.container {
width: 100%;
width: 820px;
height: 340px;
display: flex;
gap: 10px;
margin-inline: 50px;
}
.card {
min-width: 70px;
height: 100%;
border-radius: 30px;
overflow: hidden;
display: flex;
align-items: flex-end;
flex-grow: 1;
cursor: pointer;
position: relative;
transition: flex-grow 0.5s cubic-bezier(0.16, 1, 0.3, 1);
--transition-timing: 0.35s;
}
/* .card.active {
flex-grow: 100;
} */
.card:hover {
flex-grow: 7;
}
.card > .background {
position: absolute;
inset: 0;
object-fit: cover;
object-position: center;
filter: brightness(0.4);
z-index: -1;
transition: var(--transition-timing) ease;
}
.card:hover > .background {
filter: brightness(1);
}
.card > .card-content {
display: flex;
align-items: center;
position: absolute;
left: 10px;
right: 10px;
bottom: 20px;
overflow: hidden;
transition: var(--transition-timing);
z-index: 10;
}
.card:hover > .card-content {
inset: 20px;
top: auto;
}
.card-content > * {
transition: var(--transition-timing);
}
.card-content > .profile-image {
min-width: 50px;
max-width: 50px;
height: 50px;
border: 1px solid white;
display: flex;
justify-content: center;
align-items: center;
border-radius: 50%;
overflow: hidden;
}
.card:hover .profile-image {
border: 1px solid rgb(110, 252, 205);
}
.profile-image > svg {
stroke: #fefefe;
}
.card:hover .profile-image > svg {
stroke: rgb(110, 252, 205);
}
.card-content > .title {
white-space: pre;
margin-left: 10px;
translate: 0 100%;
opacity: 0;
}
.card:hover .title {
opacity: 1;
translate: 0 0;
}
.card > .backdrop {
position: absolute;
left: 0;
right: 0;
bottom: 0;
height: 100px;
z-index: 0;
background: linear-gradient(to bottom, transparent, rgba(0, 0, 0, 0.7));
}