当前位置:首页 > 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;
}

商品卡片样式

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

css商城制作

.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;
}

购物车侧边栏

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

css商城制作

.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%;
  }
}

动画效果

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

@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 精灵图制作方法 准备工具 图像编辑软件(如 Photoshop、GIMP 或在线工具) CSS 代码编辑器 步骤 收集图像资源 将需要合并的小图标或图片整理到一个文件夹中,确保这些图片尺寸…

如何制作css雪碧图

如何制作css雪碧图

什么是CSS雪碧图 CSS雪碧图(CSS Sprite)是一种将多个小图标或背景图像合并到一张大图中的技术,通过CSS的background-position属性控制显示特定部分。这种技术可以减少HT…

css 边框制作

css 边框制作

基础边框设置 使用 border 属性可快速设置边框样式、宽度和颜色: .element { border: 1px solid #000; /* 宽度 | 样式 | 颜色 */ } 样式选…

css制作导航栏

css制作导航栏

水平导航栏 使用 display: inline-block 或 flexbox 创建水平导航栏是最常见的方法。 <nav class="horizontal-nav"> &…

div css制作导航

div css制作导航

导航栏的基本结构 使用HTML的<nav>标签包裹导航链接,内部通常采用无序列表<ul>和列表项<li>结构。示例代码如下: <nav> <…

css制作图片

css制作图片

使用CSS创建图片效果 CSS可以通过多种方式实现图片的显示、处理和特效。以下是几种常见的方法: 使用background-image属性 在CSS中可以通过background-image属性将图…