Codepen | Responsive Product Card Html Css
.product-card:hover .product-img transform: scale(1.03);
@media (max-width: 480px) .cards-grid gap: 1.2rem; .product-card max-width: 100%; flex-basis: 100%; .badge font-size: 0.65rem; padding: 0.2rem 0.7rem;
.star-filled color: #f5b342; font-size: 0.9rem;
<!-- micro interaction: simple console feedback for demo (optional, but shows JS integration) --> <script> (function() // Add subtle interactive feedback for buttons — keeps the codepen alive and realistic const allButtons = document.querySelectorAll('.btn-add'); allButtons.forEach(btn => btn.addEventListener('click', function(e) e.preventDefault(); // get product title from sibling element (card content hierarchy) const card = this.closest('.product-card'); const titleElem = card?.querySelector('.product-title'); const productName = titleElem ? titleElem.innerText : 'Product'; // Provide temporary micro feedback const originalText = this.innerHTML; this.innerHTML = '✓ Added!'; this.style.backgroundColor = '#1f8a4c'; setTimeout(() => this.innerHTML = originalText; this.style.backgroundColor = '#101d2f'; , 1000); // Optional log: feel free to remove, but good for demo console.log(`🛍️ Added "$productName" to cart (demo interaction)`); ); ); )(); </script> </body> </html> responsive product card html css codepen
/* card content */ .card-content padding: 1.5rem 1.25rem 1.6rem; display: flex; flex-direction: column; flex: 1;
.product-category font-size: 0.7rem; text-transform: uppercase; letter-spacing: 1px; font-weight: 600; color: #5b6e8c; margin-bottom: 0.6rem;
.current-price font-size: 1.7rem; font-weight: 800; color: #101d2f; letter-spacing: -0.5px; .product-card:hover .product-img transform: scale(1.03)
.discount-badge-text background: #fee2e2; color: #c2412c; font-size: 0.7rem; font-weight: 700; padding: 0.2rem 0.6rem; border-radius: 30px;
.product-description font-size: 0.85rem; line-height: 1.45; color: #4a5b7a; margin-bottom: 1.3rem; display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
/* simple utility for footer / demo context */ .demo-note text-align: center; margin-top: 3rem; font-size: 0.75rem; color: #2c3e50; font-weight: 500; background: rgba(255,255,240,0.7); backdrop-filter: blur(4px); display: inline-block; width: auto; padding: 0.5rem 1.2rem; border-radius: 100px; .container-footer display: flex; justify-content: center; margin-top: 2rem; </style> </head> <body> @media (max-width: 480px) .cards-grid gap: 1.2rem
/* image container - maintains ratio and responsiveness */ .card-media position: relative; background: #f4f7fc; overflow: hidden; aspect-ratio: 1 / 1; /* classic square product image, looks great */ width: 100%;
/* responsive card grid wrapper — perfect for product listing */ .cards-grid display: flex; flex-wrap: wrap; justify-content: center; align-items: stretch; gap: 2rem; max-width: 1400px; margin: 0 auto;
.old-price font-size: 0.9rem; font-weight: 500; color: #9aaec9; text-decoration: line-through;
.product-img width: 100%; height: 100%; object-fit: cover; display: block; transition: transform 0.4s cubic-bezier(0.2, 0.9, 0.4, 1.1);
/* badge / discount tag (optional modern flair) */ .badge position: absolute; top: 1rem; left: 1rem; background: rgba(0, 0, 0, 0.7); backdrop-filter: blur(4px); color: white; font-size: 0.7rem; font-weight: 600; padding: 0.3rem 0.85rem; border-radius: 40px; letter-spacing: 0.3px; z-index: 2; font-family: inherit;