当前位置:首页 > CSS

css商城制作

2026-04-01 14:11:11CSS

布局设计

使用Flexbox或Grid布局实现响应式设计。Flexbox适合一维布局,Grid适合二维复杂布局。Flexbox示例:

.product-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  justify-content: space-between;
}

Grid示例:

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

商品卡片样式

设置统一商品卡片样式,包含图片、标题、价格和按钮:

.product-card {
  border: 1px solid #ddd;
  border-radius: 8px;
  overflow: hidden;
  transition: transform 0.3s ease;
}
.product-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}
.product-image {
  width: 100%;
  height: 200px;
  object-fit: cover;
}
.product-info {
  padding: 15px;
}
.price {
  color: #e63946;
  font-weight: bold;
  font-size: 1.2rem;
}
.add-to-cart {
  background: #457b9d;
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
}

导航栏设计

创建固定顶部导航栏,包含logo、搜索框和购物车图标:

.navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 5%;
  background: white;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
  position: sticky;
  top: 0;
  z-index: 100;
}
.search-bar {
  flex-grow: 1;
  margin: 0 20px;
}
.search-bar input {
  width: 70%;
  padding: 8px 15px;
  border-radius: 20px;
  border: 1px solid #ddd;
}
.cart-icon {
  position: relative;
}
.cart-count {
  position: absolute;
  top: -8px;
  right: -8px;
  background: red;
  color: white;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 12px;
}

购物车侧边栏

实现可滑动的购物车侧边栏:

.cart-sidebar {
  position: fixed;
  top: 0;
  right: -400px;
  width: 400px;
  height: 100vh;
  background: white;
  box-shadow: -2px 0 10px rgba(0,0,0,0.1);
  transition: right 0.3s ease;
  z-index: 1000;
  padding: 20px;
  overflow-y: auto;
}
.cart-sidebar.active {
  right: 0;
}
.cart-item {
  display: flex;
  margin-bottom: 15px;
  border-bottom: 1px solid #eee;
  padding-bottom: 15px;
}
.cart-item-image {
  width: 80px;
  height: 80px;
  object-fit: cover;
  margin-right: 15px;
}

响应式调整

添加媒体查询确保移动端友好:

@media (max-width: 768px) {
  .product-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  }
  .navbar {
    padding: 10px;
    flex-wrap: wrap;
  }
  .search-bar {
    order: 3;
    width: 100%;
    margin: 10px 0;
  }
  .search-bar input {
    width: 100%;
  }
  .cart-sidebar {
    width: 90%;
    right: -90%;
  }
}

动画效果

添加微交互提升用户体验:

css商城制作

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
.product-card {
  animation: fadeIn 0.5s ease forwards;
}
.add-to-cart {
  transition: background 0.2s ease;
}
.add-to-cart:hover {
  background: #1d3557;
}
.add-to-cart:active {
  transform: scale(0.95);
}

标签: 商城css
分享给朋友:

相关文章

css右导航栏制作

css右导航栏制作

CSS右导航栏制作方法 固定定位法 使用position: fixed将导航栏固定在视窗右侧,结合right和top属性控制位置。示例代码: .right-navbar { position:…

css下拉箭头的制作

css下拉箭头的制作

使用伪元素制作下拉箭头 通过CSS的::after或::before伪元素结合边框属性创建箭头。设置元素的position: relative,伪元素使用绝对定位调整位置。 .dropdown {…

css制作许愿墙六块

css制作许愿墙六块

CSS 制作许愿墙六块布局 使用 CSS 创建一个六块许愿墙布局可以通过多种方式实现,以下是两种常见的方法:使用 CSS Grid 或 Flexbox。以下代码示例展示了如何实现这两种布局。 方法一…

css制作

css制作

CSS 基础语法 CSS(层叠样式表)用于描述HTML元素的样式。一个基本的CSS规则由选择器和声明块组成。选择器指定要样式化的HTML元素,声明块包含一个或多个属性-值对,用花括号 {} 包裹。…

vue实现商城

vue实现商城

Vue 实现商城的基本步骤 使用 Vue.js 实现商城需要结合前端框架、状态管理、路由和 API 交互等功能。以下是关键步骤和实现方法。 项目初始化 使用 Vue CLI 或 Vite 初始化项目…

css表格制作表格

css表格制作表格

CSS 表格制作方法 基础表格结构 使用HTML的<table>标签创建表格框架,搭配<tr>(行)、<td>(单元格)和<th>(表头)标签: &l…