教程 css tutorial

卡片组件库

卡片组件是网页设计中常用的模块,用于承载内容和交互。通过灵活的 CSS 样式和结构,可以构建出多样化且易复用的卡片组件。


组件特点

  • 支持阴影和圆角
  • 布局灵活,可用于列表或网格
  • 响应式适配不同屏幕
  • 支持标题、内容、按钮等常见元素

示例代码

在线代码演示
源码
<!DOCTYPE html>
<html lang="zh-CN">

<head> <meta charset="UTF-8" /> <title>卡片组件库示例</title> <style> * { box-sizing: border-box; }

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  margin: 20px;
  background-color: #f7f9fc;
  color: #333;
}

.card-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 20px;
}

.card {
  background: white;
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  padding: 20px;
  transition: box-shadow 0.3s ease;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.card:hover {
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
}

.card h3 {
  margin-top: 0;
  margin-bottom: 10px;
  font-size: 1.25rem;
  color: #2c3e50;
}

.card p {
  flex-grow: 1;
  font-size: 1rem;
  color: #555;
  margin-bottom: 20px;
}

.card button {
  align-self: flex-start;
  padding: 8px 16px;
  background-color: #3498db;
  border: none;
  color: white;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background-color 0.3s ease;
}

.card button:hover {
  background-color: #2980b9;
}

</style> </head>

<body> <div class="card-container"> <div class="card"> <h3>卡片标题一</h3> <p>这是一段示例内容,用于展示卡片的文本排版和样式效果。</p> <button>了解更多</button> </div> <div class="card"> <h3>卡片标题二</h3> <p>卡片组件可以灵活使用于列表、网格等多种布局,支持响应式调整。</p> <button>查看详情</button> </div> <div class="card"> <h3>卡片标题三</h3> <p>设计简洁且有交互反馈,提升用户体验。</p> <button>立即使用</button> </div> </div> </body>

</html>