css制作淘宝首页
布局结构分析
淘宝首页采用典型的电商布局,包含顶部导航栏、搜索框、轮播图、分类入口、商品推荐等模块。使用Flexbox或Grid布局实现响应式设计。
基础样式设置
全局样式需重置默认边距和字体,设置基础颜色变量:
:root {
--main-color: #FF5000; /* 淘宝主色调 */
--bg-color: #F5F5F5;
--text-dark: #333;
--text-light: #999;
}
body {
margin: 0;
font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
background-color: var(--bg-color);
}
顶部导航栏实现
固定定位的导航栏包含Logo、搜索框和用户入口:

.navbar {
position: fixed;
top: 0;
width: 100%;
height: 48px;
background: white;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
display: flex;
align-items: center;
padding: 0 10px;
z-index: 100;
}
.search-box {
flex: 1;
margin: 0 15px;
height: 32px;
border-radius: 16px;
background: #F0F0F0;
display: flex;
align-items: center;
padding: 0 10px;
}
轮播图区域
使用swiper.js等库实现自动轮播效果:
.banner {
margin-top: 48px;
height: 160px;
overflow: hidden;
position: relative;
}
.banner img {
width: 100%;
height: 100%;
object-fit: cover;
}
分类图标网格
采用Flexbox布局实现九宫格分类入口:

.category-grid {
display: flex;
flex-wrap: wrap;
background: white;
padding: 10px 0;
}
.category-item {
width: 20%;
text-align: center;
padding: 8px 0;
}
.category-icon {
width: 40px;
height: 40px;
}
商品卡片样式
商品列表使用Grid布局,卡片包含图片、标题和价格:
.product-list {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 8px;
padding: 8px;
}
.product-card {
background: white;
border-radius: 6px;
overflow: hidden;
}
.product-image {
width: 100%;
height: 160px;
object-fit: cover;
}
.price {
color: var(--main-color);
font-weight: bold;
}
底部导航栏
固定定位的底部Tab栏:
.tab-bar {
position: fixed;
bottom: 0;
width: 100%;
height: 50px;
background: white;
display: flex;
border-top: 1px solid #EEE;
}
.tab-item {
flex: 1;
text-align: center;
line-height: 50px;
}
响应式适配
通过媒体查询适配不同屏幕尺寸:
@media (min-width: 768px) {
.product-list {
grid-template-columns: repeat(4, 1fr);
}
.category-item {
width: 12.5%;
}
}






