此项目为刚学完html和css时个人完成,在各方面还是有一些瑕疵,供大家学习使用.
实现效果:
项目文件列表:
图片素材都可以在小米商城找到
源码:小米商城: 刚学习html/css自己独立写的第一个项目,还是有不少瑕疵
html部分:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="css/小米商城.css">
<link rel="stylesheet" href="https://unpkg.com/swiper/swiper-bundle.min.css" />
</head>
<body>
<!-- 上部页面 不包含下面的变色背景部分 -->
<!-- 最顶部导航栏 -->
<div class="set-topbar">
<div class="container">
<div class="topbar-nav">
<a href="#" class="topbar-a">小米商城</a><span class="sep">|</span>
<a href="#" class="topbar-a">MIUI</a><span class="sep">|</span>
<a href="#" class="topbar-a">IoT</a><span class="sep">|</span>
<a href="#" class="topbar-a">云服务</a><span class="sep">|</span>
<a href="#" class="topbar-a">天星数科</a><span class="sep">|</span>
<a href="#" class="topbar-a">有品</a><span class="sep">|</span>
<a href="#" class="topbar-a">小爱开放平台</a><span class="sep">|</span>
<a href="#" class="topbar-a">企业团购</a><span class="sep">|</span>
<a href="#" class="topbar-a">资质证照</a><span class="sep">|</span>
<a href="#" class="topbar-a">协议规则</a><span class="sep">|</span>
<a href="#" class="topbar-a">下载app</a><span class="sep">|</span>
<a href="#" class="topbar-a">智能生活</a><span class="sep">|</span>
<a href="#" class="topbar-a">Select Location</a>
</div>
<a href="#" class="topbar-shoppingcart topbar-a">购物车(0)</a>
<div class="shopping-cart-detail"></div>
<div class="siteUserInfo">
<a href="#" class="topbar-a">登录</a><span class="sep">|</span>
<a href="#" class="topbar-a">注册</a><span class="sep">|</span>
<a href="#" class="topbar-a">消息通知</a>
</div>
</div>
</div>
<!-- 网站头部 -->
<div class="site-header">
<div class="container">
<a href="#" class="logo"></a>
<ul class="nav-list">
<li class="nav-category nav-space"></li>
<li class="nav-category">
<a href="#">小米手机</a></li>
<li class="nav-category">
<a href="#">RedMi红米</a></li>
<li class="nav-category">
<a href="#">电视</a></li>
<li class="nav-category">
<a href="#">笔记本</a></li>
<li class="nav-category">
<a href="#">家电</a></li>
<li class="nav-category">
<a href="#">路由器</a></li>
<li class="nav-category">
<a href="#">智能硬件</a></li>
<li class="nav-category">
<a href="#">服务</a></li>
<li class="nav-category">
<a href="#">社区</a></li>
</ul>
<div class="search-area">
<input type="submit" value="搜索" class="search-button"><input type="text" value=" 小米11" class="search-content">
</div>
<div class="shoppingcart-detail">
</div>
</div>
</div>
<!-- home-page部分 -->
<div class="home-page">
<!-- 滚动播放栏部分 -->
<div class="swiper-container site-show container ">
<ul class="site-category-list">
<li>
<a href="#">手机 电话卡</a>
</li>
<li>
<a href="#">电视 盒子</a>
</li>
<li>
<a href="#">笔记本 显示器</a>
</li>
<li>
<a href="#">家电 插线板</a>
</li>
<li>
<a href="#">出行 穿戴</a>
</li>
<li>
<a href="#">智能 路由器</a>
</li>
<li>
<a href="#">电源 配件</a>
</li>
<li>
<a href="#">健康 儿童</a>
</li>
<li>
<a href="#">耳机 音响</a>
</li>
<li>
<a href="#">生活 箱包</a>
</li>
</ul>
<div class="swiper-wrapper">
<div class="swiper-slide slide">
<img src="miui/bg1.jpg" alt="">
</div>
<div class="swiper-slide slide">
<img src="miui/bg2.webp" alt="">
</div>
</div>
<div class="swiper-pagination"></div>
</div>
</div>
<!-- 推荐栏 -->
<div class="container home-area">
<ul class="home-channel-list">
<li>
<a href="#">
<img src="miui/home-channel1.png" alt="" class="channel-logo">
<p>小米秒杀</p>
</a>
</li>
<li>
<a href="#">
<img src="miui/home-channel2.png" alt="" class="channel-logo">
<p>企业团购</p>
</a>
</li>
<li>
<a href="#">
<img src="miui/home-channel3.png" alt="" class="channel-logo">
<p>F码通行</p>
</a>
</li>
<li>
<a href="#">
<img src="miui/home-channel4.png" alt="" class="channel-logo">
<p>米粉卡</p>
</a>
</li>
<li>
<a href="#">
<img src="miui/home-channel5.png" alt="" class="channel-logo">
<p>以旧换新</p>
</a>
</li>
<li>
<a href="#">
<img src="miui/home-channel6.png" alt="" class="channel-logo">
<p>话费充值</p>
</a>
</li>
</ul>
<ul class="homePromoList">
<li>
<a href="#" class="promo-item">
<img src="miui/promo1.jpg" alt="">
</a>
</li>
<li>
<a href="#" class="promo-item">
<img src="miui/promo2.jpg" alt="">
</a>
</li>
<li>
<a href="#" class="promo-item">
<img src="miui/promo3.png" alt="">
</a>
</li>
</ul>
</div>
</div>
<!-- 下部页面 背景变色 -->
<div class="main-page">
<div class="container">
<a href="#" class="main-banner-box">
<img src="miui/banner1.webp" alt="">
</a>
</div>
<div class="container">
<h2 class="title">手机</h2>
<a href="#" class="see-more">查看更多</a>
</div>
<div class="container">
<div class="left">
<a href="#">
<img src="miui/box1-left1.webp" alt="">
</a>
</div>
<ul class="right">
<li class="right-item-up">
<a href="" class="sell-item">
<img src="miui/phone1.webp" style="width: 160px;height: 160px;" alt="">
<h3 class="item-title">Note 10 Pro</h3>
<p class="desc">天玑1100年度旗舰芯,VC液冷散热</p>
<span class="num">1699元起</span>
</a>
</li>
<li class="right-item-up">
<a href="" class="sell-item">
<img src="miui/phone2.webp" style="width: 160px;height: 160px;" alt="">
<h3 class="item-title">RedMi Note 10 5G</h3>
<p class="desc">5G小金刚,旗舰长续航</p>
<span class="num">1099元起</span>
</a>
</li>
<li class="right-item-up">
<a href="" class="sell-item">
<img src="miui/phone3.webp" style="width: 160px;height: 160px;" alt="">
<h3 class="item-title">小米MIX FOLD</h3>
<p class="desc">折叠大屏 | 自研芯片</p>
<span class="num">9999元起</span>
</a>
</li>
<li class="right-item-up">
<a href="" class="sell-item">
<img src="miui/phone4.webp" style="width: 160px;height: 160px;" alt="">
<h3 class="item-title">小米11 Ultra</h3>
<p class="desc">1/1.12"GN2 | 2K四微曲屏</p>
<span class="num">5499元起 <em class="dazhe-price">5999元</em></span>
</a>
</li>
<li class="right-item">
<a href="" class="sell-item">
<img src="miui/phone5.webp" style="width: 160px;height: 160px;" alt="">
<h3 class="item-title">小米11 Pro</h3>
<p class="desc">1/1.12"GN2 | 骁龙888</p>
<span class="num">4499元起 <em class="dazhe-price">4999元</em></span>
</a>
</li>
<li class="right-item">
<a href="" class="sell-item">
<img src="miui/phone6.webp" style="width: 160px;height: 160px;" alt="">
<h3 class="item-title">小米11 青春版</h3>
<p class="desc">小米11 青春版 轻薄</p>
<span class="num">2099元起 <em class="dazhe-price">2299元</em></span>
</a>
</li>
<li class="right-item">
<a href="" class="sell-item">
<img src="miui/phone7.webp" style="width: 160px;height: 160px;" alt="">
<h3 class="item-title">K40 游戏增强版</h3>
<p class="desc">轻薄电竞设计</p>
<span class="num">1999元起</span>
</a>
</li>
<li class="right-item">
<a href="" class="sell-item">
<img src="miui/phone8.webp" style="width: 160px;height: 160px;" alt="">
<h3 class="item-title">黑鲨4 Pro</h3>
<p class="desc">黑鲨4 Pro</p>
<span class="num">3999元起</span>
</a>
</li>
</ul>
</div>
<br>
</div>
<!-- 底边栏 -->
<div class="footer container">
<ul class="footer-service">
<li><a href="#">预约维修服务</a></li>
<li><a href="#">7天无理由退货</a></li>
<li><a href="#">15天免费换货</a></li>
<li><a href="#">满69包邮</a></li>
<li><a href="#" class="last">520余家售后网点</a></li>
</ul>
<div class="footer-link"></div>
</div>
<br>
<br>
<br>
<br>
<script src="https://unpkg.com/swiper/swiper-bundle.min.js"></script>
<script src="js/script.js"></script>
</body>
</html>
css部分:
* {
margin: 0px;
padding: 0px;
}
li {
list-style: none;
}
a {
text-decoration: none;
}
img {
width: 100%;
height: 100%;
}
/* 这个可以拿出来当通用容器格式 */
.container {
/* height: 100%; */
overflow: hidden;
width: 1226px;
margin: 0 auto;
}
/* 网站最顶部栏 的内容在这里 */
.set-topbar {
/* 最外层容器 */
height: 40px;
width: device-width;
background-color: #333;
font-size: 12px;
color: #b0b0b0;
}
.topbar-a {
float: left;
padding: 5px;
line-height: 40px;
color: #b0b0b0;
padding: 0px;
}
.topbar-a:hover {
color: white;
}
.topbar-nav {
float: left
}
.set-topbar .container .topbar-nav a {
float: left;
}
.siteUserInfo {
float: right;
margin-right: 25px;
/* position: relative; */
}
.sep {
float: left;
color: #424242;
margin: 0px;
line-height: 40px;
margin: 0 3.6px;
}
.topbar-a:hover {
color: white;
}
.topbar-shoppingcart {
width: 120px;
height: 40px;
display: block;
float: right;
padding: 0;
text-align: center;
background-color: #424242;
}
.topbar-shoppingcart:hover {
background-color: #fff;
color: #ff6700;
}
.shopping-cart-detail {
display: none;
position: absolute;
top: 40px;
/* right: 146px; */
width: 200px;
height: 100px;
background: pink;
}
/* 网站头部 */
.site-header {
margin-top: 0px;
height: 100px;
background-color: white;
/* overflow: hidden; */
}
.site-header .container {
overflow: hidden;
}
/* .header-logo {
height: 100px;
width: 56px;
background-color: pink;
} */
.site-header .container .logo {
display: block;
float: left;
height: 62px;
width: 56px;
padding: 0px;
margin: 19px 0px;
background-image: url(../miui/logo-mi2.png);
/* 设置背景图片大小 */
background-size: 56px;
background-repeat: no-repeat;
}
.site-header .container .nav-list {
float: left;
/* width: 1100px; */
width: 820px;
height: 88px;
padding-left: 30px;
padding-top: 12px;
font-size: 16px;
}
.site-header .container .nav-list a {
color: black;
}
.site-header .container .nav-list a:hover {
color: #ff7f00;
}
.nav-list .nav-category {
float: left;
padding: 26px 10px 38px 10px;
}
.nav-space {
width: 127px;
height: 88px;
padding-right: 15px;
}
.site-header .container .search-area {
float: right;
height: 100px;
width: 300px;
/* background-color: pink; */
}
.search-content {
float: right;
width: 220px;
/* height: 48px; */
margin: 25px 0px;
border: 1px solid #e0e0e0;
line-height: 48px;
}
.search-button {
float: right;
width: 50px;
height: 50px;
margin-top: 25px;
background-color: white;
border: 1px solid #e0e0e0;
}
.search-button:hover,
.search-content:hover {
border-color: #ff7f00;
}
.search-button:hover {
color: white;
background-color: #ff7f00;
}
.search-content:focus {
border-color: #ff7f00;
}
.site-header .container .shoppingcart-detail {
display: none;
position: absolute;
right: 146px;
height: 100px;
width: 200px;
background-color: pink;
z-index: 1010;
}
/*
============================
滚动播放栏部分
============================
*/
.home-page {
width: device-width;
overflow: hidden;
}
.container .site-category-list {
position: absolute;
/* float: left; */
/* background-color: #a09a97; */
background-color: rgba(105, 101, 101, .6);
}
/* .slide {
float: left;
z-index: 1000;
} */
/* .site-show {
background-size: 1226px;
background-image: url(../miui/bg1.jpg);
background-repeat: no-repeat;
} */
.site-category-list {
z-index: 1004;
}
.container .site-category-list li {
width: 204px;
height: 46px;
padding-left: 30px;
line-height: 42px;
}
.container .site-category-list li:hover {
background-color: #ff6700;
}
.container .site-category-list li a {
color: #f6f5f5;
}
/*
============================
推荐栏部分
============================
*/
/* 推荐栏左侧部分 */
.home-area {
margin-top: 20px;
height: 190px;
}
.container .home-channel-list {
float: left;
width: 228px;
height: 170px;
/* padding: 3px; */
}
.container .home-channel-list li {
float: left;
width: 76px;
height: 75px;
padding-top: 10px;
background-color: #5f5750;
}
.container .home-channel-list li a {
text-align: center;
font-size: 12px;
color: #cccac7;
}
.container .home-channel-list li a img {
display: block;
width: 24px;
height: 24px;
margin: 0 auto;
padding-top: 10px;
}
/* 推荐栏右侧部分 */
.container .homePromoList li {
float: left;
width: 316px;
height: 170px;
/* background-color: orange; */
margin-left: 16px;
/* box-shadow: 0px 17px 16px -7px rgba(0, 0, 0, 0.4); */
}
.container .homePromoList li:hover {
box-shadow: 0px 17px 16px -7px rgba(0, 0, 0, 0.4);
}
/*
====================================
下部商品页面部分, 页面背景变色为分界线
====================================
*/
/* banner栏位 */
.main-page {
background-color: #f5f5f5;
width: device-width;
overflow: hidden;
}
.main-banner-box {
float: left;
margin: 20px 0px;
}
.main-page .container .title {
float: left;
line-height: 58px;
font-weight: 400;
color: #333333;
}
.main-page .container .see-more {
float: right;
line-height: 58px;
color: #333;
}
.main-page .container .see-more:hover {
color: #ff6700;
font-size: 14px;
}
/* 商品栏位 */
.container .left {
float: left;
width: 234px;
height: 614px;
/* background-color: orange; */
}
.container .right {
float: right;
width: 992px;
height: 630px;
/* background-color: red; */
}
.container .right .right-item-up {
margin-bottom: 14px;
}
/* 左下边距为14px */
.right-item,
.right-item-up {
float: left;
width: 238px;
height: 260px;
background-color: white;
margin-left: 10px;
padding: 20px 0;
}
.right-item:hover,
.right-item-up:hover {
box-shadow: 0px 17px 16px -7px rgba(0, 0, 0, 0.4);
}
.sell-item {
display: block;
}
.sell-item img {
display: block;
margin: 0 auto;
}
.item-title {
text-align: center;
font-weight: 400;
font-size: 14px;
margin: 10px 0;
}
.desc {
font-size: 12px;
color: #b0b0b0;
text-align: center;
margin-bottom: 5px;
}
.num {
display: block;
font-size: 14px;
text-align: center;
color: #ff6700;
}
.dazhe-price {
color: #b0b0b0;
font-style: normal;
text-decoration: line-through;
}
/*
====================================
底边栏
====================================
*/
.footer .footer-service {
height: 80px;
/* background-color: orange; */
border-bottom: 1px solid #e0e0e0;
}
.footer .footer-service li {
float: left;
width: 244px;
height: 25px;
/* background-color: pink; */
text-align: center;
padding: 27.5px 0px;
font-size: 16px;
}
.footer .footer-service li a {
display: block;
color: #616161;
border-right: 1px solid #e0e0e0;
}
.footer .footer-service li .last {
border: none;
}
.footer .footer-service li a:hover {
color: #ff6700;
}
js部分
var shopping_cart = document.querySelector('.topbar-shoppingcart');
var cart_detail = document.querySelector('.shoppingcart-detail');
shopping_cart.onclick = function() {
}
//实现购物车细节的效果
var shopping_cart_detail = document.querySelector('.shopping-cart-detail');
var topbar_shoppingcart = document.querySelector('.topbar-shoppingcart');
topbar_shoppingcart.addEventListener('mousemove', function(e) {
shopping_cart_detail.style.display = 'block';
console.log(this.offsetLeft);
console.log(this.style.width);
shopping_cart_detail.style.left = (this.offsetLeft).toString() + 'px';
console.log('test1');
})
topbar_shoppingcart.addEventListener('mouseout', function(e) {
shopping_cart_detail.style.display = 'none';
console.log('test2');
})
//实现图片轮播效果,网上抠的代码
var swiper = new Swiper(".site-show", {
slidesPerView: 1,
spaceBetween: 30,
keyboard: {
enabled: true
},
pagination: {
el: ".swiper-pagination",
clickable: true
},
autoplay: {
delay: 2500,
disableOnInteraction: false,
},
loop: true,
});