A self-contained block of content — media, title, text, actions. Mostly a styling exercise; the base version needs no JS at all.
Pseudocode
Structure
A wrapper (.card) holds an optional media block, a body (title + text), and an optional footer (actions/price/buttons).
Cards are almost never alone — they’re usually laid out in a grid or a wrapped row.
Style
Rounded corners plus a border or shadow so the card reads as a distinct surface; overflow: hidden so the media block respects that corner radius instead of poking past it.
Consistent internal spacing (padding on the body, a gap between title/text/actions) matters more than any single flashy property.
Features
Static cards need no JS.
A common bit of interactivity: clamping long text to a couple of lines with a “Read more” toggle — reusing the height-transition trick from the tabs and accordion notes.
Basic card
<div class="card-grid"> <article class="card"> <div class="card-media" style="background:#6366f1">🏔️</div> <div class="card-body"> <h3 class="card-title">Trailhead Jacket</h3> <p class="card-text">Lightweight shell for shoulder-season hikes, packs down to nothing.</p> </div> <div class="card-actions"> <span class="card-price">$128</span> <button class="card-btn">Add to cart</button> </div> </article> <article class="card"> <div class="card-media" style="background:#0ea5e9">🌊</div> <div class="card-body"> <h3 class="card-title">Reef Sandals</h3> <p class="card-text">Quick-dry straps and a grippy sole for wet rocks and tide pools.</p> </div> <div class="card-actions"> <span class="card-price">$54</span> <button class="card-btn">Add to cart</button> </div> </article> <article class="card"> <div class="card-media" style="background:#f97316">🏜️</div> <div class="card-body"> <h3 class="card-title">Canyon Cap</h3> <p class="card-text">Wide brim, UPF 50+, and a chin cord for windy ridgelines.</p> </div> <div class="card-actions"> <span class="card-price">$32</span> <button class="card-btn">Add to cart</button> </div> </article></div>
.card-clamp starts at a fixed height (2.6em, about two lines) with overflow: hidden. The toggle reads the panel’s real height with scrollHeight — the same trick as the tabs and accordion notes — and animates between the collapsed height and that value.
<article class="card" id="ec-card"> <div class="card-media" style="background:#14b8a6">🧊</div> <div class="card-body"> <h3 class="card-title">Glacier Bottle</h3> <div class="card-clamp" id="ec-clamp"> <p class="card-text"> Double-walled steel, keeps drinks cold for 24 hours or hot for 12. The wide mouth fits ice cubes and most filter straws, and the powder-coated finish resists scratches on the trail. Comes in five colors, all made from 90% recycled steel. </p> </div> <button class="card-toggle" id="ec-toggle">Read more</button> </div></article>