当前位置: 首页 > news >正文

挑战用React封装100个组件【002】

项目地址
https://github.com/hismeyy/react-component-100

组件描述
组件适用于需要展示图文信息的场景,比如产品介绍、用户卡片或任何带有标题、描述和可选图片的内容展示

样式展示

在这里插入图片描述

代码展示

InfoCard.tsx
import './InfoCard.css'interface InfoCardProps {title: string;description: string;imgSrc: string;imgAlt?: string;
}const InfoCard = ({ title, description, imgSrc, imgAlt = title
}: InfoCardProps) => {return (<div className='info-card'><div className='img'>{imgSrc && <img src={imgSrc} alt={imgAlt} />}</div><div className="info"><h6>{title}</h6><p>{description}</p></div></div>)
}export default InfoCard
InfoCard.css
.info-card {box-sizing: border-box;width: 350px;height: 450px;border-radius: 15px;background-color: #F5F5F5;box-shadow: 3px 3px 6px rgba(0, 0, 0, 0.3);display: flex;flex-direction: column;align-items: left;padding: 15px;cursor: pointer;transform-origin: center;position: relative;overflow: hidden;
}.info-card .img {width: 320px;height: 320px;overflow: hidden;display: flex;justify-content: center;align-items: center;border-radius: 8px;box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.3);transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}.info-card .img img {width: 100%;height: 100%;object-fit: cover;transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}.info-card .info {margin: 20px 5px 0;height: 60px;position: relative;z-index: 1;transition: transform 0.3s ease;
}.info-card .info h6 {all: unset;display: block;width: 100%;font-size: 16px;font-weight: bold;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;transition: color 0.3s ease;
}.info-card .info p {all: unset;display: -webkit-box;width: 100%;margin-top: 10px;font-size: 12px;-webkit-line-clamp: 3;-webkit-box-orient: vertical;overflow: hidden;text-overflow: ellipsis;word-wrap: break-word;line-height: 1.3;line-clamp: 2;box-orient: vertical;
}.info-card:hover .img {transform: scale(1.02);
}.info-card:hover .img img {transform: scale(1.1);
}.info-card:hover .info h6 {color: #f08a5d;
}

使用

App.tsx
import './App.css'
import InfoCard from './components/card/infoCard02/InfoCard'function App() {return (<><InfoCardtitle="Web全栈开发指南"description="全面的Web开发学习指南,涵盖前端技术、后端开发、数据库设计等多个领域的知识。本课程将帮助你构建完整的开发技能体系。"imgSrc="https://images.unsplash.com/photo-1517694712202-14dd9538aa97?w=600&q=80"/></>)
}export default App
http://www.lryc.cn/news/493864.html

相关文章:

  • MarkDown-插入图片-图片url地址的生成获取方法
  • 插值、拟合和回归分析的相关知识
  • 【小白学机器学习42】进行多次抽样,样本的分布参数和总体的分布参数的关系
  • 链动星海 质引未来|中信银行加码科技金融 “接力式”服务助力“新质生产力”释放
  • 黑马2024AI+JavaWeb开发入门Day02-JS-VUE飞书作业
  • 云计算基础-期末复习
  • Java GET请求 请求参数在Body中使用Json格式传参
  • AI数据分析工具(一)
  • go结构体匿名“继承“方法冲突时继承优先顺序
  • 【049】基于51单片机语音录放【Proteus仿真+Keil程序+报告+原理图】
  • 《软件项目管理》期末-复习题及参考答案
  • milvus 通俗易懂原理
  • 什么是撞库、拖库和洗库?
  • 安卓-碎片的使用入门
  • 华为IPD流程学习之——深入解读123页华为IPD流程体系设计方法论PPT
  • DriveMLLM:一个专为自动驾驶空间理解任务设计的大规模基准数据集
  • 高效处理 iOS 应用中的大规模礼物数据:以直播项目为例(1-礼物池)
  • python的函数与递归
  • RabbitMQ学习-Seven
  • 中科亿海微SoM模组——波控处理软硬一体解决方案
  • 开源法律、政策和实践
  • 【计算视觉算法与应用】金字塔,下采样Gaussian Pyramid. 上采用 Laplacian Pyramid (code: py)
  • 基于BERT的语义分析实现
  • DNS查询工具
  • ODB 框架
  • Ubuntu WiFi检测
  • QILSTE H4-108TCG高亮纯lu光LED灯珠 发光二极管LED
  • IP与“谷子”齐飞,阅文“乘势而上”?
  • Java阶段三05
  • C# yield 关键字