Layout · 08 of 23
Expandable Card
Layout expansion
<div class="expand-card">
<div class="ec-header">
<h3>Expand Me</h3>
<span class="ec-icon">+</span>
</div>
<div class="ec-content">
<p>Additional details revealed with a shared layout transition feel.</p>
</div>
</div>
.expand-card {
width: 100%;
max-width: 320px;
background: #222;
color: #f0f0f5;
border-radius: 8px;
padding: 1rem;
cursor: pointer;
overflow: hidden;
transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
max-height: 60px; /* collapsed: only the header shows */
}
.expand-card.open {
max-height: 200px;
background: #2a2a30;
}
.ec-header {
display: flex;
justify-content: space-between;
align-items: center;
}
.ec-header h3 {
margin: 0;
}
/* The + rotates 45deg into an x */
.ec-icon {
transition: transform 0.4s;
}
.expand-card.open .ec-icon {
transform: rotate(45deg);
}
/* Content fades in slightly after the height expands */
.ec-content {
margin-top: 1rem;
opacity: 0;
transition: opacity 0.3s 0.1s;
}
.expand-card.open .ec-content {
opacity: 1;
}
var expandCard = document.querySelector('.expand-card');
expandCard.addEventListener('click', function () {
expandCard.classList.toggle('open');
});