Blogger Information
Blog 37
fans 1
comment 0
visits 32625
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
使用position、flex弹性盒子仿写京东移动端
Jason Pu?
Original
745 people have browsed it

前言

经过一段时间的学习,掌握了盒子模型,弹性盒子的知识,为了验证成果,我使用前面学习到的知识来做一个仿写京东移动端的页面,主要仿写了页眉,页脚,导航,秒杀四个区块的内容

思路及心得:

1.header页眉及footer页脚可以使用position:fixed固定定位。
2.maion主体使用position:absolute实现定位,top:header的高度,bottom:footer的高度,right:0,lift:0,实现三大区块相互独立,互不相犯。
3.内部小组件使用flex弹性盒子实现

容易忽略的知识点:

flex属性:
flex是flex-grow, flex-shrink 和 flex-basis的简写,默认值为0 1 auto;
第一个值是:放大比例,默认为0,即如果存在剩余空间,也不放大。
第二个值是:缩小比例,默认为1,即如果空间不足,该项目将缩小。
第三个值是:项目占据的主轴空间

项目成果:

HTML代码:

  1. <title>JD手机端</title>
  2. <link rel="stylesheet" href="jdicon/iconfont.css">
  3. <link rel="stylesheet" href="css/index.css">
  4. </head>
  5. <body>
  6. <!-- 页眉 -->
  7. <div class="header">
  8. <!-- 三条杠: -->
  9. <span class="iconfont icon-daohang"></span>
  10. <!-- 搜索框 -->
  11. <div class="searchbar">
  12. <p class="jd">JD</p>
  13. <span class="iconfont icon-fangdajing"></span>
  14. <input type="text" class="search_input" value="罗技鼠标">
  15. </div>
  16. <div class="login">登录</div>
  17. </div>
  18. <!-- 主体: -->
  19. <div class="main">
  20. <!-- 导航区 -->
  21. <div class="nav">
  22. <div class="nav_items">
  23. <img src="jdimg/jdnav1.png" alt="">
  24. <p>京东超市</p>
  25. </div>
  26. <div class="nav_items">
  27. <img src="jdimg/jdnav2.png" alt="">
  28. <p>数码电器</p>
  29. </div>
  30. <div class="nav_items">
  31. <img src="jdimg/jdnav3.png" alt="">
  32. <p>京东服饰</p>
  33. </div>
  34. <div class="nav_items">
  35. <img src="jdimg/jdnav4.png" alt="">
  36. <p>京东生鲜</p>
  37. </div>
  38. <div class="nav_items">
  39. <img src="jdimg/jdnav5.png" alt="">
  40. <p>京东到家</p>
  41. </div>
  42. <div class="nav_items">
  43. <img src="jdimg/jdnav6.png" alt="">
  44. <p>充值缴费</p>
  45. </div>
  46. <div class="nav_items">
  47. <img src="jdimg/jdnav7.png" alt="">
  48. <p>9.9元拼</p>
  49. </div>
  50. <div class="nav_items">
  51. <img src="jdimg/jdnav8.png" alt="">
  52. <p>领券</p>
  53. </div>
  54. <div class="nav_items">
  55. <img src="jdimg/jdnav9.png" alt="">
  56. <p>领金贴</p>
  57. </div>
  58. <div class="nav_items">
  59. <img src="jdimg/jdnav10.png" alt="">
  60. <p>PLUS会员</p>
  61. </div>
  62. </div>
  63. <!-- 秒杀区 -->
  64. <div class="ms">
  65. <div class="msbar">
  66. <div class="msslogon">京东秒杀</div>
  67. <div class="notice">
  68. <div class="mstime">10点场</div>
  69. <div class="msreverstime">00</div>
  70. <span>:</span>
  71. <div class="msreverstime">00</div>
  72. <span>:</span>
  73. <div class="msreverstime">00</div>
  74. </div>
  75. <div class="morems">更多秒杀</div>
  76. </div>
  77. <div class="msbody">
  78. <div class="content">
  79. <img src="jdimg/jdms1.jpg" alt="">
  80. <div class="newprice">¥100</div>
  81. <div class="oldprice">¥199</div>
  82. </div>
  83. <div class="content">
  84. <img src="jdimg/jdms2.jpg" alt="">
  85. <div class="newprice">¥100</div>
  86. <div class="oldprice">¥199</div>
  87. </div>
  88. <div class="content">
  89. <img src="jdimg/jdms3.jpg" alt="">
  90. <div class="newprice">¥100</div>
  91. <div class="oldprice">¥199</div>
  92. </div>
  93. <div class="content">
  94. <img src="jdimg/jdms4.jpg" alt="">
  95. <div class="newprice">¥100</div>
  96. <div class="oldprice">¥199</div>
  97. </div>
  98. </div>
  99. </div>
  100. </div>
  101. <!-- 页脚 -->
  102. <div class="footer">
  103. <div id="fist">
  104. <span class="iconfont icon-shouye"></span>
  105. <p>首页</p>
  106. </div>
  107. <div>
  108. <span class="iconfont icon-leimupinleifenleileibie2"></span>
  109. <p>分类</p>
  110. </div>
  111. <div>
  112. <span class="iconfont icon-jingxi"></span>
  113. <p>京喜</p>
  114. </div>
  115. <div>
  116. <span class="iconfont icon-gouwucheman"></span>
  117. <p>购物车</p>
  118. </div>
  119. <div>
  120. <span class="iconfont icon-denglu"></span>
  121. <p>未登陆</p>
  122. </div>
  123. </div>
  124. </body>

CSS代码:

  1. @import 'reset.css';
  2. /* 页眉部分开始 */
  3. .header{
  4. width: 100%;
  5. height: 4.5rem;
  6. color:#fff;
  7. background-color: #E43130;
  8. position: fixed;
  9. top: 0;
  10. font-size: 1.4rem;
  11. display: flex;
  12. align-items: center;
  13. z-index: 100;
  14. }
  15. /* 搜索框整体 */
  16. .header .searchbar{
  17. flex:6;
  18. text-align: center;
  19. display:flex;
  20. justify-content: flex-start;
  21. border-radius: 3rem;
  22. background-color: #fff;
  23. padding: 0.5rem;
  24. }
  25. /* 三条杠: */
  26. .header .icon-daohang{
  27. font-size: 2.5rem;
  28. flex:1;
  29. flex: 0 1 4rem;
  30. text-align: center;
  31. }
  32. /* JD */
  33. .header .searchbar .jd{
  34. font-size: 2rem;
  35. color: #E43130;
  36. flex: 0 1 4rem;
  37. line-height: 2rem;
  38. text-align: center;
  39. }
  40. /* 放大镜 */
  41. .header .searchbar .icon-fangdajing{
  42. font-size: 1.8rem;
  43. color:gray;
  44. text-align: center;
  45. border-left: 1px solid gray;
  46. flex: 0 1 4rem;
  47. line-height: 1.8rem;
  48. }
  49. /* 输入框 */
  50. .header .searchbar .search_input {
  51. outline: none;
  52. flex: auto;
  53. border:none;
  54. color: gray;
  55. }
  56. /* 登录 */
  57. .header .login{
  58. flex:1;
  59. text-align: center;
  60. }
  61. /* 页眉部分结束 */
  62. /* 主体部分开始: */
  63. .main{
  64. position: absolute;
  65. top:4.5rem;
  66. bottom:4.5rem;
  67. left: 0;
  68. right: 0;
  69. font-size:1.4rem;
  70. }
  71. /* 导航区开始 */
  72. .main .nav{
  73. padding-top:1rem;
  74. display: flex;
  75. flex-flow: row wrap;
  76. align-content: space-between;
  77. }
  78. .main .nav img{
  79. width:4rem;
  80. height: 4rem;
  81. }
  82. .main .nav .nav_items{
  83. flex: 1 1 20%;
  84. text-align: center;
  85. }
  86. .main .nav .nav_items p{
  87. color:gray;
  88. font-size: 1rem;
  89. }
  90. /* 导航区结束 */
  91. /* 秒杀活动开始 */
  92. .main .ms{
  93. padding:1rem;
  94. margin: 0.1rem 0;
  95. }
  96. .main .ms .msbar {
  97. display:flex;
  98. justify-content: space-between;
  99. align-items: center;
  100. height: 3rem;
  101. }
  102. .main .ms .msbar .morems {
  103. font-size:1.5rem;
  104. color:#FB3522;
  105. }
  106. .main .ms .msbar .msslogon {
  107. font-size: 1.6rem;
  108. }
  109. .main .ms .msbar .notice{
  110. display: flex;
  111. line-height: 2rem;
  112. text-align: center;
  113. }
  114. .main .ms .msbar .notice .time{
  115. font-size:1.5rem;
  116. }
  117. .main .ms .msbar .notice .msreverstime{
  118. background-color: #E43130;
  119. color:white;
  120. border-radius: 0.5rem;
  121. }
  122. /* 秒杀展示主体开始 */
  123. .main .ms .msbody {
  124. display: flex;
  125. justify-content:space-between;
  126. }
  127. .main .ms .msbody .content{
  128. text-align: center;
  129. }
  130. .main .ms .msbody .content img{
  131. width:calc( 25vw - 1rem );
  132. }
  133. .main .ms .msbody .content .newprice {
  134. color:#E43130;
  135. font-size: 1.5rem;
  136. }
  137. .main .ms .msbody .content .oldprice{
  138. color:gray;
  139. text-decoration: line-through;
  140. }
  141. /* 秒杀展示主体结束 */
  142. /* 秒杀活动结束 */
  143. /* 主体部分结束: */
  144. /* 页脚部分开始 */
  145. .footer{
  146. width: 100%;
  147. height: 4.5rem;
  148. background-color: #fff;
  149. position: fixed;
  150. bottom: 0;
  151. display: flex;
  152. justify-content: space-around;
  153. align-items: center;
  154. text-align: center;
  155. }
  156. .footer > div > .iconfont {
  157. font-size: 2.5rem;
  158. color:#8B8B8B;
  159. }
  160. .footer > div > p {
  161. font-size: 1rem;
  162. color:#8B8B8B;
  163. }
  164. /* 页脚部分结束 */
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