Design and Implementation of Cards in Modern Web Development
Dec 07, 2024 pm 12:30 PMCards are one of the most versatile components in modern web design. They are used to present information in a concise and visually attractive way, from products in online stores to articles on blogs. In this guide, we will explore different implementations and best practices.
Anatomy of a Card
A typical card consists of several elements:
<div> <h2> Implementaciones </h2> <h3> 1. Card Básica con CSS </h3> <pre class="brush:php;toolbar:false">.card { width: 300px; border-radius: 8px; overflow: hidden; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); transition: transform 0.2s ease; } .card:hover { transform: translateY(-4px); } .card-image { width: 100%; height: 200px; object-fit: cover; } .card-content { padding: 16px; } .card-title { margin: 0 0 8px; font-size: 1.25rem; } .card-description { color: #666; line-height: 1.5; } .card-footer { display: flex; justify-content: space-between; align-items: center; padding-top: 16px; margin-top: 16px; border-top: 1px solid #eee; }
2. Card with Tailwind CSS
<div> <h3> 3. Componente React con TypeScript </h3> <pre class="brush:php;toolbar:false">interface CardProps { image: string; title: string; description: string; action?: () => void; meta?: string; } const Card: React.FC<cardprops> = ({ image, title, description, action, meta }) => { return ( <div classname="card"> <img src="/static/imghw/default1.png" data-src="imagen.jpg" class="lazy" alt="{title}" classname="card-image" loading="lazy"> <div classname="card-content"> <h2 classname="card-title">{title}</h2> <p classname="card-description">{description}</p> <div classname="card-footer"> {action && ( <button onclick="{action}" classname="card-button"> Ver más </button> )} {meta && <span classname="card-meta">{meta}</span>} </div> </div> </div> ); }; </cardprops>
4. Vue 3 component
<template> <div> <h2> Patrones de Dise?o </h2> <h3> 1. Card Grid Responsiva </h3> <pre class="brush:php;toolbar:false">.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 24px; padding: 24px; }
2. Cards with Aspect Ratio
.card-image-container { position: relative; padding-top: 56.25%; /* 16:9 Aspect Ratio */ } .card-image { position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: cover; }
3. Skeleton Loading
.card-skeleton { animation: pulse 1.5s infinite; } @keyframes pulse { 0% { opacity: 0.6; } 50% { opacity: 1; } 100% { opacity: 0.6; } }
Accessibility
<div> <h2> Mejores Prácticas </h2> <ol> <li> <strong>Optimización de Imágenes</strong> </li> </ol> <pre class="brush:php;toolbar:false">import Image from 'next/image'; <image src="%7BimageUrl%7D" alt="{title}" width="{300}" height="{200}" placeholder="blur" blurdataurl="{thumbnailUrl}"></image>
- Image Error Handling
const handleImageError = (e: React.SyntheticEvent<htmlimageelement>) => { e.currentTarget.src = '/placeholder.jpg'; }; <img src="/static/imghw/default1.png" data-src="imagen.jpg" class="lazy" onerror="{handleImageError}" alt="{title}"> </htmlimageelement>
- Text Truncation
.card-title { overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
Animations
/* Hover Effects */ .card { transition: all 0.3s ease; } .card:hover { transform: translateY(-4px); box-shadow: 0 12px 24px rgba(0, 0, 0, 0.15); } /* Click Effect */ .card:active { transform: translateY(-2px); box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1); }
Performance Considerations
- Lazy Loading
<img src="/static/imghw/default1.png" data-src="imagen.jpg" class="lazy" loading="lazy" alt="Design and Implementation of Cards in Modern Web Development">
- Intersection Observer
useEffect(() => { const observer = new IntersectionObserver( (entries) => { entries.forEach(entry => { if (entry.isIntersecting) { // Cargar contenido } }); }, { threshold: 0.1 } ); observer.observe(cardRef.current); return () => observer.disconnect(); }, []);
Conclusion
Cards are fundamental components in modern web design. A good implementation should consider:
- Responsive design
- Accessibility
- Performance
- User experience
- Code maintainability
Additional Resources
- Material Design Cards
- Tailwind UI Components
- MDN Web Components
The above is the detailed content of Design and Implementation of Cards in Modern Web Development. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Java and JavaScript are different programming languages, each suitable for different application scenarios. Java is used for large enterprise and mobile application development, while JavaScript is mainly used for web page development.

JavaScriptcommentsareessentialformaintaining,reading,andguidingcodeexecution.1)Single-linecommentsareusedforquickexplanations.2)Multi-linecommentsexplaincomplexlogicorprovidedetaileddocumentation.3)Inlinecommentsclarifyspecificpartsofcode.Bestpractic

The following points should be noted when processing dates and time in JavaScript: 1. There are many ways to create Date objects. It is recommended to use ISO format strings to ensure compatibility; 2. Get and set time information can be obtained and set methods, and note that the month starts from 0; 3. Manually formatting dates requires strings, and third-party libraries can also be used; 4. It is recommended to use libraries that support time zones, such as Luxon. Mastering these key points can effectively avoid common mistakes.

PlacingtagsatthebottomofablogpostorwebpageservespracticalpurposesforSEO,userexperience,anddesign.1.IthelpswithSEObyallowingsearchenginestoaccesskeyword-relevanttagswithoutclutteringthemaincontent.2.Itimprovesuserexperiencebykeepingthefocusonthearticl

JavaScriptispreferredforwebdevelopment,whileJavaisbetterforlarge-scalebackendsystemsandAndroidapps.1)JavaScriptexcelsincreatinginteractivewebexperienceswithitsdynamicnatureandDOMmanipulation.2)Javaoffersstrongtypingandobject-orientedfeatures,idealfor

JavaScripthassevenfundamentaldatatypes:number,string,boolean,undefined,null,object,andsymbol.1)Numbersuseadouble-precisionformat,usefulforwidevaluerangesbutbecautiouswithfloating-pointarithmetic.2)Stringsareimmutable,useefficientconcatenationmethodsf

Event capture and bubble are two stages of event propagation in DOM. Capture is from the top layer to the target element, and bubble is from the target element to the top layer. 1. Event capture is implemented by setting the useCapture parameter of addEventListener to true; 2. Event bubble is the default behavior, useCapture is set to false or omitted; 3. Event propagation can be used to prevent event propagation; 4. Event bubbling supports event delegation to improve dynamic content processing efficiency; 5. Capture can be used to intercept events in advance, such as logging or error processing. Understanding these two phases helps to accurately control the timing and how JavaScript responds to user operations.

Java and JavaScript are different programming languages. 1.Java is a statically typed and compiled language, suitable for enterprise applications and large systems. 2. JavaScript is a dynamic type and interpreted language, mainly used for web interaction and front-end development.
