基于html和vue.js以及其他编程技术打造一个仿京东购物网站平台
效果展示
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>仿京东商城</title>
<link rel="stylesheet" href="css/style.css">
<script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
</head>
<body>
<div id="app">
<header>
<div class="top-bar">
<div class="container">
<div class="location">北京</div>
<div class="user-menu">
<a href="#">登录</a>
<a href="#">注册</a>
<a href="cart.html">购物车</a>
</div>
</div>
</div>
<div class="search-area">
<div class="container">
<div class="logo">
<img src="images/logo.png" alt="Logo">
</div>
<div class="search-box">
<input type="text" v-model="searchKeyword" placeholder="请输入搜索关键词">
<button @click="handleSearch">搜索</button>
</div>
</div>
</div>
</header>
<nav class="main-nav">
<div class="container">
<ul>
<li><a href="index.html">首页</a></li>
<li><a href="phones.html">手机</a></li>
<li><a href="computers.html">电脑</a></li>
<li><a href="digital.html">数码</a></li>
<li><a href="appliances.html">家电</a></li>
</ul>
</div>
</nav>
<main>
<div class="container">
<div class="banner">
<!-- 轮播图位置 -->
</div>
<div class="product-grid">
<div class="product-item" v-for="product in products" :key="product.id">
<img :src="product.image" :alt="product.title">
<h3>{{ product.title }}</h3>
<p class="price">{{ product.price }}</p>
<button class="add-to-cart" @click="addToCart(product)">加入购物车</button>
</div>
</div>
</div>
</main>
<footer>
<div class="container">
<p>© 2024 仿京东商城. All rights reserved. <a href="admin-login.html" class="admin-link">管理后台</a></p>
</div>
</footer>
</div>
<script src="js/main.js"></script>
</body>
</html>
上面写了导航栏和基本结构,包括页面基本布局,HTML引言通常是放在HTML文档的头部,用来指定文档的字符编码和其他元数据信息。一般来说,引言是通过标签来定义的。
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
/* 恢复容器样式 */
.container {
max-width: 1200px;
margin: 0 auto;
padding: 0 15px;
padding-left: 20px; /* 添加左右边距 */
padding-right: 20px; /* 添加左右边距 */
}
/* 顶部导航栏 */
.top-bar {
background: #e3e4e5;
padding: 5px 0;
margin-bottom: 10px; /* 添加间距 */
position: sticky;
top: 0;
z-index: 1000;
}
.top-bar .user-menu {
float: right;
}
.top-bar a {
margin-left: 15px;
color: #999;
text-decoration: none;
}
/* 搜索区域 */
.search-area {
padding: 20px 0;
margin-bottom: 20px; /* 添加间距 */
background: #f5f5f5; /* 添加背景色 */
border-radius: 8px; /* 添加圆角 */
box-shadow: 0 2px 10px rgba(0,0,0,0.1); /* 添加阴影 */
position: sticky;
top: 40px; /* 顶部导航栏高度 */
z-index: 999;
}
.search-area .logo {
float: left;
width: 150px;
}
.search-box {
margin-left: 160px;
position: relative;
}
.search-box input {
width: 100%;
max-width: 500px;
height: 36px;
padding: 0 10px;
border: 2px solid #e1251b;
border-radius: 4px 0 0 4px; /* 添加圆角 */
font-size: 16px; /* 调整字体大小 */
}
.search-box button {
width: 80px;
height: 36px;
background: #e1251b;
color: white;
border: none;
cursor: pointer;
border-radius: 0 4px 4px 0; /* 添加圆角 */
font-size: 16px; /* 调整字体大小 */
}
/* 搜索建议框样式 */
.search-suggestions {
position: absolute;
top: 100%;
left: 0;
right: 80px; /* 搜索按钮宽度 */
background: white;
border: 1px solid #ddd;
border-top: none;
max-height: 300px;
overflow-y: auto;
display: none;
z-index: 1000;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
border-radius: 0 0 4px 4px; /* 添加圆角 */
}
/* 主导航栏样式 */
.main-nav {
background: #e1251b;
padding: 0;
margin-bottom: 20px; /* 添加间距 */
}
.main-nav ul {
list-style: none;
display: flex;
margin: 0;
padding: 0;
width: 100%;
}
.main-nav li {
margin: 0;
flex: 1;
text-align: center;
}
.main-nav a {
color: white;
text-decoration: none;
font-size: 16px;
padding: 15px 0;
display: block;
transition: all 0.3s;
width: 100%;
}
.main-nav a:hover,
.main-nav a.active {
background: rgba(255,255,255,0.1);
}
/* 移除之前的 Bootstrap 导航样式 */
.main-nav .nav-link {
color: white;
padding: 8px 15px;
}
/* 恢复商品网格布局 */
.product-grid {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 20px;
margin: 20px 0;
}
.product-item {
padding: 15px;
border: 1px solid #eee;
text-align: center;
margin-bottom: 20px;
height: 100%;
border-radius: 0.25rem;
transition: all 0.3s;
}
.product-item:hover {
box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
}
.product-item img {
max-width: 100%;
}
.product-item h3 {
margin: 10px 0;
font-size: 14px;
}
.price {
color: #e1251b;
font-size: 18px;
margin: 10px 0;
}
/* 按钮样式使用 Bootstrap 的 btn 类 */
.add-to-cart {
width: 100%;
}
/* 购物车样式 */
.cart-items {
margin: 20px 0;
}
.cart-item {
display: flex;
align-items: center;
padding: 15px;
border: 1px solid #eee;
margin-bottom: 10px;
border-radius: 4px;
}
.cart-item img {
width: 100px;
height: 100px;
object-fit: cover;
margin-right: 20px;
}
.item-info {
flex: 1;
}
.quantity {
display: flex;
align-items: center;
margin: 10px 0;
}
quantity button {
width: 30px;
height: 30px;
background: #f5f5f5;
border: 1px solid #ddd;
cursor: pointer;
}
quantity input {
width: 50px;
height: 30px;
text-align: center;
margin: 0 10px;
}
.remove-item {
padding: 5px 15px;
background: #999;
color: white;
border: none;
cursor: pointer;
margin-left: 20px;
}
/* 购物车样式适配 Bootstrap */
.cart-summary {
background: #f8f9fa;
border-radius: 0.25rem;
padding: 1rem;
}
.cart-summary {
text-align: right;
padding: 20px;
background: #f5f5f5;
margin-top: 20px;
border-radius: 4px;
}
.total-price {
color: #e1251b;
font-size: 24px;
font-weight: bold;
margin: 0 10px;
}
.checkout {
background: #e1251b;
color: white;
border: none;
padding: 10px 30px;
font-size: 16px;
cursor: pointer;
margin-top: 10px;
}
/* 页脚 */
footer {
background: #f5f5f5;
padding: 20px 0;
text-align: center;
margin-top: 30px;
}
/* 响应式布局基础设置 */
html {
font-size: 16px;
}
body {
min-width: 320px;
}
img {
max-width: 100%;
height: auto;
}
/* 搜索匹配商品样式 */
.product-item.search-match {
border: 2px solid #e1251b;
box-shadow: 0 0 10px rgba(225, 37, 27, 0.1);
transform: scale(1.02);
}
.product-item.search-match::before {
content: '最佳匹配';
position: absolute;
top: 10px;
right: 10px;
background: #e1251b;
color: white;
padding: 2px 8px;
border-radius: 3px;
font-size: 12px;
}
/* 提示框样式 */
.alert-box {
position: fixed;
top: 20px;
left: 50%;
transform: translateX(-50%);
background: #e1251b;
color: white;
padding: 10px 20px;
border-radius: 4px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
z-index: 1000;
font-size: 14px;
}
/* 媒体查询 */
@media screen and (max-width: 1200px) {
html {
font-size: 15px;
}
.container {
width: 100%;
padding: 0 10px;
}
}
@media screen and (max-width: 992px) {
html {
font-size: 14px;
}
.search-area {
text-align: center;
}
.search-area .logo {
float: none;
margin: 0 auto 15px;
}
.search-box {
margin-left: 0;
}
.main-nav li {
margin-right: 15px;
}
}
@media screen and (max-width: 768px) {
html {
font-size: 13px;
}
.top-bar .location {
display: none;
}
.product-grid {
grid-template-columns: repeat(2, 1fr);
}
/* 购物车响应式 */
.cart-item {
flex-direction: column;
text-align: center;
}
.cart-item img {
margin: 0 auto 15px;
}
.item-info {
width: 100%;
}
.quantity {
justify-content: center;
}
.main-nav a {
padding: 12px 0;
font-size: 14px;
}
.main-nav ul {
flex-wrap: nowrap; /* 确保不换行 */
}
.main-nav li {
margin: 0; /* 移除所有边距 */
}
}
@media screen and (max-width: 576px) {
html {
font-size: 12px;
}
.product-grid {
grid-template-columns: repeat(1, 1fr);
}
.search-box input {
width: calc(100% - 80px);
}
.main-nav ul {
display: flex;
justify-content: space-between;
padding: 0 10px;
}
.main-nav li {
margin-right: 0;
}
.cart-summary {
text-align: center;
}
}
上面是index页面基本css样式,在网页布局中,CSS(层叠样式表)起着非常重要的作用。CSS用来控制网页元素的样式和布局,包括元素的大小、位置、颜色、字体等。严格按照基本css方式写和补充,
手机页面
注册页面
购物车页面
后台管理页面
最后,总体基本实现前端展示和后端管理基本功能,简洁干练完成。