css制作店铺
CSS制作店铺布局
使用CSS制作店铺布局需要关注整体结构、商品展示、导航和响应式设计。以下是一些关键方法和代码示例。
基础布局结构
使用Flexbox或Grid创建店铺的主框架。Flexbox适合一维布局,Grid适合复杂的二维布局。
.store-container {
display: grid;
grid-template-columns: 1fr 3fr;
gap: 20px;
}
.sidebar {
background: #f5f5f5;
padding: 15px;
}
.main-content {
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;
}
.product-card:hover {
transform: translateY(-5px);
}
.product-image {
width: 100%;
height: 200px;
object-fit: cover;
}
.product-info {
padding: 15px;
}
.product-title {
font-size: 1.1rem;
margin: 0 0 10px;
}
.product-price {
font-weight: bold;
color: #e63946;
}
.add-to-cart {
background: #007bff;
color: white;
border: none;
padding: 8px 15px;
border-radius: 4px;
cursor: pointer;
}
导航和筛选
侧边栏可以用于分类筛选或导航。
.filter-section {
margin-bottom: 20px;
}
.filter-title {
font-weight: bold;
margin-bottom: 10px;
}
.filter-option {
margin-bottom: 5px;
}
.filter-option label {
margin-left: 5px;
}
响应式设计
使用媒体查询确保店铺在不同设备上显示良好。
@media (max-width: 768px) {
.store-container {
grid-template-columns: 1fr;
}
.main-content {
grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
}
动画和交互效果
添加悬停效果和加载动画提升用户体验。
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
.product-card {
animation: fadeIn 0.5s ease-in-out;
}
.loading-spinner {
border: 4px solid rgba(0, 0, 0, 0.1);
border-radius: 50%;
border-top: 4px solid #007bff;
width: 40px;
height: 40px;
animation: spin 1s linear infinite;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
主题和颜色方案
使用CSS变量便于统一调整主题颜色。

:root {
--primary-color: #007bff;
--secondary-color: #6c757d;
--background-light: #f8f9fa;
}
.product-card {
background: var(--background-light);
}
.add-to-cart {
background: var(--primary-color);
}
通过以上方法,可以创建一个美观且功能完善的店铺布局。根据实际需求调整网格列数、卡片样式和响应式断点。






