当前位置:   article > 正文

购物网站HTML(首页)_简单购物网站代码html

简单购物网站代码html

HTML代码

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>首页</title>
  6. <script src="js/Untitled-4.js"></script>
  7. <link href="CSS/首页.css" rel="stylesheet" type="text/css">
  8. <link href="CSS/whole.css" rel="stylesheet" type="text/css">
  9. </head>
  10. <body>
  11. <!--header begin-->
  12. <div class="header">
  13. <div class="header_logo"> <img src="images/huawei_logo.png" /></div>
  14. <div class="header_text"> <a href= "HTML/登录.html">登录</a>|<a href="HTML/登录.html">注册</a> </div>
  15. </div>
  16. <!--header end-->
  17. <!--nav begin-->
  18. <div class="nav">
  19. <ul class="nav_in">
  20. <li><a href="首页.html">首页</a></li>
  21. <li><a href="HTML/华为专区.html">华为专区</a></li>
  22. <li><a href="HTML/鸿蒙智选.html">鸿蒙智联</a></li>
  23. <li><a href="HTML/华为智选.html">华为智选</a></li>
  24. <li><a href="HTML/HarmonyOS.html">HarmonyOS</a></li>
  25. <li><a href= "HTML/购物车.html">我的购物车</a></li>
  26. </ul>
  27. </div>
  28. <!--nav end-->
  29. <!--banner begin-->
  30. <div class="main">
  31. <!-- 左按钮 -->
  32. <a href="javascript:;" class="left">&lt;</a>
  33. <!-- 右按钮 -->
  34. <a href="javascript:;" class="right">&gt;</a>
  35. <!-- 滚动区 -->
  36. <ul>
  37. <li><img src="images/ban1.jpg"></li>
  38. <li><img src= "images/ban2.jpg"></li>
  39. </ul>
  40. <!-- 小圆 -->
  41. <ol class="circle">
  42. </ol>
  43. </div>

CSS代码

  1. @charset "utf-8";
  2. /* CSS Document */
  3. ul,ol{
  4. list-style: none;
  5. }
  6. a{
  7. text-decoration: none;
  8. }
  9. .main{
  10. width:100%;
  11. height:455px;
  12. position:relative;
  13. overflow:hidden;
  14. margin: auto;
  15. }
  16. .left,.right{
  17. display: none;
  18. position: absolute;
  19. top: 50%;
  20. margin-top: -20px;
  21. width: 24px;
  22. height: 40px;
  23. background: rgba(0, 0, 0, .3);
  24. text-align: center;
  25. line-height: 40px;
  26. color: #fff;
  27. font-size: 18px;
  28. z-index: 2;
  29. }
  30. .right{
  31. right: 0;
  32. }
  33. .circle {
  34. position: absolute;
  35. bottom: 10px;
  36. left: 50px;
  37. }
  38. .main ul{
  39. position: absolute;
  40. left: 0;
  41. top: 0;
  42. width: 1000%;
  43. }
  44. .main ul li{
  45. float:left;
  46. }
  47. .circle li {
  48. float: left;
  49. width: 8px;
  50. height: 8px;
  51. border: 2px solid orange;
  52. margin: 0 3px;
  53. border-radius: 50%;
  54. /*鼠标经过显示小手*/
  55. cursor: pointer;
  56. }
  57. .current {
  58. background-color: orange;
  59. }
  60. .content_text{
  61. text-align: center;
  62. margin-top: 20px;
  63. }
  64. .content{
  65. width:1250px;
  66. height:1200px;
  67. margin: auto;
  68. margin-top:100px;
  69. }
  70. .content_box1{
  71. float:left;
  72. width:60%;
  73. height:500px;
  74. background:url("../images/pic1.jpg");
  75. background-size:cover;
  76. }
  77. .content_box2{
  78. float:right;
  79. background:url("../images/pic2.jpg");
  80. width:35%;
  81. height:500px;
  82. background-size:cover;
  83. }
  84. .content_box3{
  85. float:left;
  86. background:url( "../images/pic3.jpg");
  87. width:30%;
  88. height:550px;
  89. background-size:cover;
  90. margin-top:50px;
  91. }
  92. .content_box4{
  93. float:right;
  94. background:url( "../images/pic4.jpg");
  95. width:60%;
  96. height:550px;
  97. background-size:cover;
  98. margin-top:50px;
  99. }
  100. .content_box1:hover,.content_box2:hover,.content_box3:hover,.content_box4:hover{
  101. transform:scale(1.15);
  102. }
  103. .footer{
  104. width:100%;
  105. height:80px;
  106. background:#8E8E8E;
  107. text-align: center;
  108. padding-top: 30px;
  109. color:#ccc;
  110. }
  111. .footer p{
  112. line-height: 30px;
  113. font-size: 14px;
  114. }

  1. @charset "utf-8";
  2. /* CSS Document */
  3. *{margin:0;padding:0;border:0;list-style:none;}
  4. body{font-family:"微软雅黑";font-size:16px;color:#404042;}/** CSS Document */
  5. a{text-decoration:none;color:#fff;}
  6. .header{
  7. width:1000px;
  8. margin:0 auto;
  9. padding-top:20px;
  10. overflow:hidden;
  11. }
  12. .header_logo{
  13. float:left;
  14. }
  15. .header_text{
  16. float:right;
  17. }
  18. .header a{ color:#404042;}
  19. .header a:hover{color:#da5454;}
  20. .nav{width:100%;
  21. height:40px;
  22. background:#999;
  23. margin-top: 15px
  24. }
  25. .nav_in{
  26. width:980px;
  27. margin:0 auto;
  28. }
  29. .nav_in li{
  30. float:left;
  31. }
  32. .nav_in li a{
  33. display:block;
  34. line-height: 40px;
  35. padding:0 36px;
  36. }
  37. .nav_in li .current{
  38. background: #da5454;
  39. }
  40. .nav_in a:hover{background: #da5454;}
  41. .banner{
  42. width:100%;
  43. height:580px;
  44. position:relative;
  45. overflow:hidden;
  46. }
  47. .gouwuche{
  48. position: absolute;
  49. float:right;
  50. }
  51. .footer{
  52. width:100%;
  53. height:80px;
  54. background:#8E8E8E;
  55. text-align: center;
  56. padding-top:25px;
  57. color:#ccc;
  58. margin-top: 15px;
  59. }
  60. .footer p{
  61. line-height: 30px;
  62. font-size: 14px;
  63. }

JavaScript
 

  1. // JavaScript Document
  2. function animate(obj, target, callback) {
  3. // 先清除以前的定时器,只保留当前的一个定时器执行
  4. clearInterval(obj.timer);
  5. obj.timer = setInterval(function() {
  6. // 步长值写到定时器的里面
  7. // 把我们步长值改为整数 不要出现小数的问题
  8. var step = (target - obj.offsetLeft) / 10;
  9. step = step > 0 ? Math.ceil(step) : Math.floor(step);
  10. if (obj.offsetLeft == target) {
  11. // 停止动画 本质是停止定时器
  12. clearInterval(obj.timer);
  13. // 回调函数写到定时器结束里面
  14. if (callback) {
  15. // 调用函数
  16. callback();
  17. }
  18. }
  19. // 把每次加 这个步长值改为一个慢慢变小的值 步长公式:(目标值 - 现在的位置) / 10
  20. obj.style.left = obj.offsetLeft + step + 'px';
  21. }, 15);
  22. }
  23. window.addEventListener('load',function(){
  24. //1.获取元素
  25. var left = document.querySelector('.left');
  26. var right = document.querySelector('.right');
  27. var main = document.querySelector('.main');
  28. var mainWidth = main.offsetWidth;
  29. //2.鼠标经过显示左右按钮
  30. main.addEventListener('mouseenter',function(){
  31. left.style.display = 'block';
  32. right.style.display = 'block';
  33. clearInterval(timer);
  34. timer = null; // 清除定时器变量
  35. })
  36. //3.鼠标离开隐藏左右按钮
  37. main.addEventListener('mouseleave',function(){
  38. left.style.display = 'none';
  39. right.style.display = 'none';
  40. timer = setInterval(function() {
  41. //手动调用点击事件
  42. right.click();
  43. }, 2000);
  44. })
  45. //4.动态生成圆圈
  46. var ul = main.querySelector('ul')
  47. var ol = main.querySelector('.circle')
  48. for (var i = 0; i < ul.children.length; i++) {
  49. //创建一个li
  50. var li = document.createElement('li');
  51. // 记录当前小圆圈的索引号 通过自定义属性来做
  52. li.setAttribute('index', i);
  53. //插入ol
  54. ol.appendChild(li);
  55. //排他思想
  56. li.addEventListener('click', function() {
  57. //所有li清除类名
  58. for (var i = 0; i < ol.children.length; i++) {
  59. ol.children[i].className = '';
  60. }
  61. //当前li设置current类名
  62. this.className = 'current';
  63. var index = this.getAttribute('index');
  64. num = index;
  65. circle = index;
  66. animate(ul, -index * mainWidth);
  67. })
  68. }
  69. //第一个小li设置为current
  70. ol.children[0].className = 'current';
  71. // 克隆第一张图片(li)放到ul 最后面
  72. var first = ul.children[0].cloneNode(true);
  73. ul.appendChild(first);
  74. // 6.点击右按钮,图片滚动一张
  75. var num = 0;
  76. var circle = 0;
  77. var flag = true;
  78. // 7.右侧按钮
  79. right.addEventListener('click',function(){
  80. if(flag){
  81. //关闭节流阀
  82. flag = false;
  83. if(num == ul.children.length-1){
  84. ul.style.left = 0;
  85. num = 0;
  86. }
  87. num++;
  88. animate(ul, -num*mainWidth,function(){
  89. flag = true;
  90. });
  91. circle++;
  92. if (circle == ol.children.length) {
  93. circle = 0;
  94. }
  95. // 调用函数
  96. circleChange();
  97. }
  98. });
  99. // 8.左侧按钮
  100. left.addEventListener('click',function(){
  101. if(flag){
  102. flag = false;
  103. if(num == 0){
  104. num = ul.children.length - 1;
  105. ul.style.left = -num * mainWidth + 'px';
  106. }
  107. num--;
  108. animate(ul, -num*mainWidth, function(){
  109. flag = true;
  110. });
  111. circle--;
  112. if (circle < 0) {
  113. circle = ol.children.length - 1;
  114. }
  115. // 调用函数
  116. circleChange();
  117. }
  118. });
  119. function circleChange() {
  120. // 先清除其余小圆圈的current类名
  121. for (var i = 0; i < ol.children.length; i++) {
  122. ol.children[i].className = '';
  123. }
  124. // 留下当前的小圆圈的current类名
  125. ol.children[circle].className = 'current';
  126. }
  127. // 自动播放轮播图
  128. var timer = setInterval(function() {
  129. //手动调用点击事件
  130. right.click();
  131. }, 2000);
  132. })

二、内容页

第一张 HTML

  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <link href="../CSS/hwzq.css" rel="stylesheet" type="text/css">
  6. <link href="../CSS/whole.css" rel="stylesheet" type="text/css">
  7. <title>华为专区</title>
  8. </head>
  9. <body>
  10. <!--header begin-->
  11. <div class="header">
  12. <div class="header_logo"> <img src="../images/huawei_logo.png" /></div>
  13. <div class="header_text"> <a href="登录.html">登录</a>|<a href="登录.html">注册</a></div>
  14. </div>
  15. <!--header end-->
  16. <!--nav begin-->
  17. <div class="nav">
  18. <ul class="nav_in">
  19. <li><a href="../首页.html">首页</a></li>
  20. <li><a href="华为专区.html">华为专区</a></li>
  21. <li><a href="鸿蒙智选.html">鸿蒙智联</a></li>
  22. <li><a href="华为智选.html">华为智选</a></li>
  23. <li><a href="HarmonyOS.html">HarmonyOS</a></li>
  24. <li><a href= "购物车.html">我的购物车</a></li>
  25. </ul>
  26. </div>
  27. <!--nav end-->
  28. <!--banner degin-->
  29. <div class="banner"> <img src="../images/nav2.jpg"></div>
  30. <!--banner end-->
  31. <!--content begin-->
  32. <h1 class="content_text">产品分类</h1>
  33. <div class="content">
  34. <div class="content_box1">
  35. <div class="conntent_box_text"><p><a href="#">手机</a></p></div>
  36. </div>
  37. <div class="content_box2">
  38. <div class="conntent_box_text"><p><a href="#">笔记本</a></p></div>
  39. </div>
  40. <div class="content_box3">
  41. <div class="conntent_box_text"><p><a href="#">平板</a></p></div>
  42. </div>
  43. <div class="content_box4">
  44. <div class="conntent_box_text"><p><a href="#">智慧屏</a></p></div>
  45. </div>
  46. <div class="content_box5">
  47. <div class="conntent_box_text"><p><a href="#">智能手表</a></p></div>
  48. </div>
  49. <div class="content_box6">
  50. <div class="conntent_box_text"> <p><a href="#">耳机</a></p></div>
  51. </div>
  52. </div>
  53. <!--content end-->
  54. <!--footer begin-->
  55. <div class="footer">
  56. </div>
  57. <!--footer end-->
  58. </body>
  59. </html>

因为有一些板块的样式是一样的,为了减少重复的编写,建一个css用来编写相同的样式

  1. @charset "utf-8";
  2. /* CSS Document */
  3. *{margin:0;padding:0;border:0;list-style:none;}
  4. body{font-family:"微软雅黑";font-size:16px;color:#404042;}/** CSS Document */
  5. a{text-decoration:none;color:#fff;}
  6. .header{
  7. width:1000px;
  8. margin:0 auto;
  9. padding-top:20px;
  10. overflow:hidden;
  11. }
  12. .header_logo{
  13. float:left;
  14. }
  15. .header_text{
  16. float:right;
  17. }
  18. .header a{ color:#404042;}
  19. .header a:hover{color:#da5454;}
  20. .nav{width:100%;
  21. height:40px;
  22. background:#999;
  23. margin-top: 15px
  24. }
  25. .nav_in{
  26. width:980px;
  27. margin:0 auto;
  28. }
  29. .nav_in li{
  30. float:left;
  31. }
  32. .nav_in li a{
  33. display:block;
  34. line-height: 40px;
  35. padding:0 36px;
  36. }
  37. .nav_in li .current{
  38. background: #da5454;
  39. }
  40. .nav_in a:hover{background: #da5454;}
  41. .banner{
  42. width:100%;
  43. height:580px;
  44. position:relative;
  45. overflow:hidden;
  46. }
  47. .gouwuche{
  48. position: absolute;
  49. float:right;
  50. }
  51. .footer{
  52. width:100%;
  53. height:80px;
  54. background:#8E8E8E;
  55. text-align: center;
  56. padding-top:25px;
  57. color:#ccc;
  58. margin-top: 15px;
  59. }
  60. .footer p{
  61. line-height: 30px;
  62. font-size: 14px;
  63. }

再根据不同的点编写一个专门的css样式

  1. @charset "utf-8";
  2. /* CSS Document */
  3. .banner{
  4. width:100%;
  5. height:580px;
  6. position:relative;
  7. overflow:hidden;
  8. }
  9. .content{
  10. width:80%;
  11. height:800px;
  12. margin: 0 auto;
  13. }
  14. .content_text{
  15. text-align: center;
  16. margin-top: 20px;
  17. }
  18. .content_box1{
  19. float:left;
  20. width:20%;
  21. height:250px;
  22. background:url( "../images/content1.jpg");
  23. background-size:cover;
  24. margin-left:125px;
  25. margin-top: 25px;
  26. }
  27. .conntent_box_text {
  28. text-align:center;
  29. float:left;
  30. width:100%;
  31. height:15px;
  32. margin-top:220px;
  33. }
  34. .conntent_box_text a{
  35. font-size: 20px;
  36. color: #000000;
  37. }
  38. .content_box2{
  39. float:left;
  40. width:20%;
  41. height:250px;
  42. background:url(" ../images/content2.jpg");
  43. background-size:cover;
  44. margin-left:125px;
  45. margin-top: 25px;
  46. }
  47. .content_box3{
  48. float:left;
  49. width:20%;
  50. height:250px;
  51. background:url( "../images/content3.jpg");
  52. background-size:cover;
  53. margin-left:125px;
  54. margin-top: 25px;
  55. }
  56. .content_box4{
  57. float:left;
  58. width:20%;
  59. height:250px;
  60. background:url( "../images/content4.jpg");
  61. background-size:cover;
  62. margin-left:125px;
  63. margin-top: 100px;
  64. }
  65. .content_box5{
  66. float:left;
  67. width:20%;
  68. height:250px;
  69. background:url( "../images/content5.jpg");
  70. background-size:cover;
  71. margin-left:125px;
  72. margin-top: 100px;
  73. }
  74. .content_box6{
  75. float:left;
  76. width:20%;
  77. height:250px;
  78. background:url( "../images/content6.jpg");
  79. background-size:cover;
  80. margin-left:125px;
  81. margin-top: 100px;
  82. }
  83. .content_box1:hover,.content_box2:hover,.content_box3:hover,.content_box4:hover,.content_box5:hover,.content_box6:hover{
  84. transform:scale(1.15);
  85. }

第二张HTML

HTML部分

  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>鸿蒙智联</title>
  6. <link href="../CSS/hmzx.css" rel="stylesheet" type="text/css">
  7. <link href="../CSS/whole.css" rel="stylesheet" type="text/css">
  8. </head>
  9. <!--header begin-->
  10. <div class="header">
  11. <div class="header_logo"> <img src="../images/huawei_logo.png" /></div>
  12. <div class="header_text"> <a href="登录.html">登录</a>|<a href="登录.html">注册</a> </div>
  13. </div>
  14. <!--header end-->
  15. <!--nav begin-->
  16. <div class="nav">
  17. <ul class="nav_in">
  18. <li><a href="../首页.html">首页</a></li>
  19. <li><a href="华为专区.html">华为专区</a></li>
  20. <li><a href="鸿蒙智选.html">鸿蒙智联</a></li>
  21. <li><a href="华为智选.html">华为智选</a></li>
  22. <li><a href="HarmonyOS.html">HarmonyOS</a></li>
  23. <li><a href= "购物车.html">我的购物车</a></li>
  24. </ul>
  25. </div>
  26. <!--nav end-->
  27. <!--banner degin-->
  28. <div class="banner"> <img src="../images/2.webp"></div>
  29. <!--banner end-->
  30. <!--banner end-->
  31. <!--content BEGIN-->
  32. <h1 class="content_text">热门推荐</h1>
  33. <div class="content">
  34. <a href="#"><div class="content_box1"></div></a>
  35. <a href="#"><div class="content_box2"></div></a>
  36. <a href="#"><div class="content_box3"></div></a>
  37. <a href="#"><div class="content_box4"></div></a>
  38. <a href="#"><div class="content_box5"></div></a>
  39. <a href="#"><div class="content_box6"></div></a>
  40. </div>
  41. <!--content end-->
  42. <!--footer begin-->
  43. <div class="footer">
  44. </div>
  45. <!--footer end-->
  46. <body>
  47. </body>
  48. </html>

css部分

  1. @charset "utf-8";
  2. /* CSS Document */
  3. .content{
  4. width:80%;
  5. height:800px;
  6. margin: 0 auto;
  7. }
  8. .content_text{
  9. text-align: center;
  10. margin-top: 20px;
  11. }
  12. .content_box1{
  13. float:left;
  14. width:20%;
  15. height:330px;
  16. background:url( "../images/2.1.jpg");
  17. background-size:cover;
  18. margin-left:125px;
  19. margin-top: 25px;
  20. }
  21. .content_box2{
  22. float:left;
  23. width:20%;
  24. height:330px;
  25. background:url( "../images/2.2.jpg");
  26. background-size:cover;
  27. margin-left:125px;
  28. margin-top: 25px;
  29. }
  30. .content_box3{
  31. float:left;
  32. width:20%;
  33. height:330px;
  34. background:url( "../images/2.3.jpg");
  35. background-size:cover;
  36. margin-left:125px;
  37. margin-top: 25px;
  38. }
  39. .content_box4{
  40. float:left;
  41. width:20%;
  42. height:330px;
  43. background:url( "../images/2.4.jpg");
  44. background-size:cover;
  45. margin-left:125px;
  46. margin-top: 25px;
  47. }
  48. .content_box5{
  49. float:left;
  50. width:20%;
  51. height:330px;
  52. background:url( "../images/2.5.jpg");
  53. background-size:cover;
  54. margin-left:125px;
  55. margin-top: 25px;
  56. }
  57. .content_box6{
  58. float:left;
  59. width:20%;
  60. height:330px;
  61. background:url( "../images/2.6.jpg");
  62. background-size:cover;
  63. margin-left:125px;
  64. margin-top: 25px;
  65. }
  66. .content_box1:hover,.content_box2:hover,.content_box3:hover,.content_box4:hover,.content_box5:hover,.content_box6:hover{
  67. transform:scale(1.15);
  68. }

效果图

watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBASHViZXJ04piF,size_20,color_FFFFFF,t_70,g_se,x_16

 watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBASHViZXJ04piF,size_20,color_FFFFFF,t_70,g_se,x_16

可以根据需要更换图片

图片来源于华为商城网站

购物网站(内容页面)_Hubert★的博客-CSDN博客icon-default.png?t=M85Bhttps://blog.csdn.net/m0_56078449/article/details/122881619

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/612220
推荐阅读
相关标签
  

闽ICP备14008679号