用css制作淘宝网页
布局结构设计
淘宝网页通常采用经典的头部、主体和底部三部分布局。头部包含导航栏、搜索框和用户入口,主体展示商品分类和推荐,底部放置版权信息和链接。
<div class="container">
<header class="header"></header>
<main class="main-content"></main>
<footer class="footer"></footer>
</div>
导航栏样式
导航栏需要固定定位,包含logo、搜索框和用户操作入口。使用flex布局实现水平排列。
.header {
position: fixed;
top: 0;
width: 100%;
height: 60px;
background: #FF0036;
display: flex;
align-items: center;
padding: 0 20px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
z-index: 1000;
}
.logo {
width: 120px;
height: 40px;
background: url('taobao-logo.png') no-repeat;
background-size: contain;
}
.search-box {
flex: 1;
margin: 0 20px;
height: 36px;
border-radius: 4px;
background: white;
display: flex;
}
.user-actions {
display: flex;
gap: 15px;
}
商品展示区
商品展示采用网格布局,每个商品卡片包含图片、标题、价格和销量信息。
.product-grid {
display: grid;
grid-template-columns: repeat(5, 1fr);
gap: 15px;
padding: 20px;
margin-top: 80px;
}
.product-card {
background: white;
border-radius: 8px;
overflow: hidden;
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
transition: transform 0.3s;
}
.product-card:hover {
transform: translateY(-5px);
}
.product-image {
width: 100%;
height: 180px;
object-fit: cover;
}
.product-info {
padding: 10px;
}
.price {
color: #FF0036;
font-weight: bold;
font-size: 18px;
}
响应式设计
使用媒体查询适配不同屏幕尺寸,在移动端调整布局和字号。
@media (max-width: 768px) {
.product-grid {
grid-template-columns: repeat(2, 1fr);
}
.header {
height: 50px;
padding: 0 10px;
}
.logo {
width: 80px;
}
}
动画效果
为按钮和交互元素添加微交互动画,提升用户体验。
.add-to-cart {
background: #FF0036;
color: white;
border: none;
padding: 8px 15px;
border-radius: 4px;
cursor: pointer;
transition: all 0.3s;
}
.add-to-cart:hover {
background: #E60033;
transform: scale(1.05);
}
底部样式
底部区域包含网站导航链接和版权信息,使用深色背景增强可读性。

.footer {
background: #333;
color: #999;
padding: 30px 0;
text-align: center;
}
.footer-links {
display: flex;
justify-content: center;
gap: 20px;
margin-bottom: 15px;
}
.footer-links a {
color: #ccc;
text-decoration: none;
}
.footer-links a:hover {
color: white;
}






