Blogger Information
Blog 16
fans 0
comment 0
visits 16196
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
仿作京东网页
Leo的博客
Original
496 people have browsed it

.

先进行整体布局

首页布局:页眉、主体、页脚、

  1. <div class="home"></div>
  2. <div class="header"></div>
  3. <div class="main>"</div>
  4. <div class="footer"></div>

添加参考线

用轮廓线不会占页面空间

  1. .home>*{
  2. outline:1px solid red
  3. }

页面样式重置

样式重置

  1. *{
  2. margin:0;
  3. padding:0;
  4. box-sizing: border-box;
  5. }
  1. html{
  2. font-size:10px;
  3. }

rem

  1. html{
  2. font-size:10px;
  3. }

用a链接去除下划线

  1. a{
  2. text-decoration:none;
  3. color:666;
  4. }
  5. li{
  6. list-style:none;
  7. }

恢复字号

在body里面恢复字号16px

  1. body{
  2. font-size:1.6rem;
  3. background-color:#f6f6f6;
  4. }

媒体查询

动态设置rem大小
从小到大,移动优先

  1. @meadia screen and(min-width:480px){
  2. html{
  3. font-size:12px;
  4. }
  5. }
  6. @meadia screen and(min-width:640px){
  7. html{
  8. font-size:14px;
  9. }
  10. }
  11. @meadia screen and(min-width:720px){
  12. html{
  13. font-size:16px;
  14. }
  15. }

把以上代码放入rest.css中

rest专门做样式重置的
放入rest后在html中关联起来

  1. <link rel="stylesheet" href="css/reset.css"/>

仿作的网站为单列三行

中间内容会溢出

页眉和页脚是固定的

视口不足,给个最小的高度
view height:视口高度
页面布局直接用grid来写
页眉页脚固定所以给个固定大小

  1. .home{
  2. min-height100vh
  3. displaygrid
  4. grid-template-rows4em 1fr 6rem
  5. }

中间主体部分

隐藏中间主体部分

  1. .home .main{
  2. height:calc(100vh-4rem-6rem);
  3. overflow-yscroll
  4. }

头部首页布局

第一部分是个按钮 加入字体图标引用

  1. <link rel="stylesheet" href="lib/font_icon/iconfont.css" />

在页眉的div中加入

  1. <span class="iconfont icon-caidan"><span>

加入搜索框加入一个块
在快中加入京东LOGO和搜索图标

  1. <div class="search">
  2. <span class="iconfont icon-jingdong "><span>
  3. <span class="iconfont icon-search"><span>
  4. <from action="">
  5. <input type="search" name="search" value="联想拯救者">
  6. </div>

登录按钮

用button来做也行

  1. <a href="">登录</a>

在css创建header

修改html的头部样式

  1. .home .header {
  2. background-color: red;
  3. display: grid;
  4. grid-template-columns: 5rem 1fr 5rem;
  5. place-items: center;
  6. color: #fff;
  7. }
  8. .home .header.icon-caidan {
  9. font-size: 2.5ren;
  10. font-weight: bolder;
  11. }
  12. .home .header a {
  13. color: white;
  14. font-size: 1.4rem;
  15. }
  16. .home .header .search {
  17. width: 100%;
  18. background-color: #fff;
  19. padding: 0.2em;
  20. border-radius: 1.5rem;
  21. display: grid;
  22. grid-template-columns: auto auto 1fr;
  23. }
  24. .home .header .search form input {
  25. min-width: 100%;
  26. outline: none;
  27. border: none;
  28. color: #888;
  29. }
  30. .home .header .search .icon-jingdong {
  31. color: #e43130;
  32. font-size: 2rem;
  33. padding: 0 0.5rem;
  34. place-self: center;
  35. }
  36. .home .header .search .icon-search {
  37. color: #888;
  38. font-size: 2rem;
  39. padding: 0 0.5rem;
  40. place-self: center;
  41. }

回到html输出:

回到html布局页脚

  1. <div class="footer">
  2. <div>
  3. <span class="iconfont icon-jingdong1"></span>
  4. <span>京东</span>
  5. </div>
  6. <div>
  7. <span class="icofont icon-fenlei2"></span>
  8. <span>分类</span>
  9. </div>
  10. <div>
  11. <span class="iconfont icon-social-jingxi"></span>
  12. <span>惊喜</span>
  13. </div>
  14. <div>
  15. <span class="iconfont icon-gouwuche"></span>
  16. <span>购物车</span>
  17. </div>
  18. <div>
  19. <span class="iconfont icon-weidengluyonghuicon"></span>
  20. <span>未登录</span>
  21. </div>
  22. </div>
  23. </div>

创建footer页脚css

  1. .home .footer {
  2. background-color: #efefef;
  3. border-top: 1px solid #ddd;
  4. display: flex;
  5. place-content: space-around;
  6. }
  7. .home .footer div {
  8. color: #888;
  9. display: flex;
  10. flex-flow: column nowrap;
  11. /* 垂直水平方向居中 */
  12. place-items: center;
  13. }
  14. .home .footer div:first-of-type {
  15. color: red;
  16. }
  17. /* 调整图标大小 */
  18. .home .footer div span:first-of-type {
  19. font-size: 2.5rem;
  20. }
  21. /* 调整文本大小 */
  22. .home .footer div span:last-of-type {
  23. font-size: 1.2rem;
  24. }

轮播图写在主体main里面

  1. <div class="main">
  2. <div class="slider">
  3. <div class="imgs">
  4. <a href="" class="active"
  5. ><img src="static/images/banner.png" alt=""
  6. /></a>
  7. <a href=""><img src="static/images/banner.png" alt="" /></a>
  8. <a href=""><img src="static/images/banner.png" alt="" /></a>
  9. </div>

同上记得引入css才有效果

  1. <link rel="stylesheet" href="css/slider.css" />

轮播图css代码

  1. .home .main .slider {
  2. width: 90%;
  3. margin: 1rem auto 2rem;
  4. }
  5. .home .main .slider img {
  6. width: 100%;
  7. border-radius: 1rem;
  8. margin-top: 1rem;
  9. }
  10. /* 初始化时,将所有轮播图片先全部隐藏,默认只显示第一个 */
  11. /* 注意,轮播图是可点击的,图片在链接元素中,所以只需要设置a标签即可 */
  12. .home .main .slider .imgs a {
  13. display: none;
  14. }
  15. /* 默认第一个轮播图激活 */
  16. .home .main .slider .imgs a.active {
  17. display: block;
  18. }
  19. /* 切换按钮容器的样式 */
  20. .home .main .slider .btns {
  21. /* flex布局,且水平居中,并上移到轮播图底部 */
  22. display: flex;
  23. justify-content: center;
  24. /* 负外距可反向移动元素,这里是向上 */
  25. margin-top: -2rem;
  26. }
  27. /* 切换按钮 */
  28. .home .main .slider .btns .item {
  29. height: 0.8rem;
  30. width: 0.8rem;
  31. border-radius: 50%;
  32. background-color: #888;
  33. margin: 0.2rem;
  34. }
  35. /* 切换按钮鼠标悬停样式 */
  36. .home .main .slider .btns .item:hover {
  37. cursor: pointer;
  38. }
  39. /* 当前默认激活的按钮样式 */
  40. .home .main .slider .btns .item.active {
  41. background-color: #e43130;
  42. }

导航区

因为都是字体图标,字体都是可点击。所以用a链接来写。

  1. <div class="navs">
  2. <ul class="nav-group active">
  3. <li>
  4. <a href=""><img src="static/images/nav/nav-1.png" alt="" /></a>
  5. <a href="">京东超市</a>
  6. </li>
  7. <li>
  8. <a href=""><img src="static/images/nav/nav-2.png" alt="" /></a>
  9. <a href="">数码电器</a>
  10. </li>
  11. <li>
  12. <a href=""><img src="static/images/nav/nav-3.png" alt="" /></a>
  13. <a href="">京东服饰</a>
  14. </li>
  15. <li>
  16. <a href=""><img src="static/images/nav/nav-4.png" alt="" /></a>
  17. <a href="">京东生鲜</a>
  18. </li>
  19. <li>
  20. <a href=""><img src="static/images/nav/nav-5.png" alt="" /></a>
  21. <a href="">京东到家</a>
  22. </li>
  23. <li>
  24. <a href=""><img src="static/images/nav/nav-6.png" alt="" /></a>
  25. <a href="">充值缴费</a>
  26. </li>
  27. <li>
  28. <a href=""><img src="static/images/nav/nav-7.png" alt="" /></a>
  29. <a href="">9.9元拼</a>
  30. </li>
  31. <li>
  32. <a href=""><img src="static/images/nav/nav-8.png" alt="" /></a>
  33. <a href="">领券</a>
  34. </li>
  35. <li>
  36. <a href=""><img src="static/images/nav/nav-9.png" alt="" /></a>
  37. <a href="">领金贴</a>
  38. </li>
  39. <li>
  40. <a href=""><img src="static/images/nav/nav-10.png" alt="" /></a>
  41. <a href="">PLUS会员</a>
  42. </li>
  43. </ul>
  44. </div>

记得再hetml关联导航区的css

新建navs.css布局导航区

用网格布局来写

  1. .home .main .navs .nav-group {
  2. display: grid;
  3. grid-template-columns: repeat(5, 1fr);
  4. }
  5. .home .main .navs .nav-group li a {
  6. font-size: 1.2rem;
  7. }
  8. .home .main .navs .nav-group li img {
  9. width: 4rem;
  10. }
  11. .home .main .navs .nav-group li {
  12. display: grid;
  13. place-items: center;
  14. }

商品区

代码比较长就不全部复制过来了

  1. <ul class="list">
  2. <li class="item">
  3. <a href=""><img src="static/images/items/item1.jpg" alt="" /></a>
  4. <div class="intro">
  5. <span>自营</span>
  6. <span>商品介绍商品介绍商品介绍商品介绍商品介绍...</span>
  7. </div>
  8. <div class="price">
  9. <span class="iconfont icon-renminbi">2877</span>
  10. <span class="sign">满减</span>
  11. <span class="other">看相似</span>
  12. </div>
  13. </li>
  14. <li class="item">
  15. <a href=""><img src="static/images/items/item2.jpg" alt="" /></a>
  16. <div class="intro">
  17. <span>自营</span>
  18. <span>商品介绍商品介绍商品介绍商品介绍商品介绍...</span>
  19. </div>
  20. <div class="price">
  21. <span class="iconfont icon-renminbi">1899</span>
  22. <span class="sign">满减</span>
  23. <span class="other">看相似</span>
  24. </div>
  25. </li>
  26. <li class="item">
  27. <a href=""><img src="static/images/items/item3.jpg" alt="" /></a>
  28. <div class="intro">
  29. <span>自营</span>
  30. <span>商品介绍商品介绍商品介绍商品介绍商品介绍...</span>
  31. </div>

创建商品区的css,list.css

  1. .home .main .list {
  2. display: grid;
  3. grid-template-columns: repeat(2, 1fr);
  4. gap: 1.5rem;
  5. padding: 1.5rem;
  6. }
  7. .home .main .list img {
  8. width: 100%;
  9. border-radius: 0.5rem;
  10. padding-bottom: 3rem;
  11. border-radius: 1rem;
  12. font-size: 1.3rem;
  13. }

输出最后结果:

Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post