博客列表 >1.移动端布局的基本思路与三种视口之间的关系 2. 实战手机页面的基本整体架构:页眉,页脚,主体等

1.移动端布局的基本思路与三种视口之间的关系 2. 实战手机页面的基本整体架构:页眉,页脚,主体等

P粉355147598
P粉355147598原创
2022年03月31日 16:58:15577浏览

前言:应处于学习阶段,此篇内容可能理解有误,仅供参考,如大神有空,还请评论纠正。实战也是需要不断的看一眼源码,自己还是不能独立构造框架。

移动端布局的基本思路

感觉只要确定好1rem = ?, 1vw =?,与pc端无异啊。

  1. :root {
  2. font-size: calc(100vw / 3.75);
  3. }

三种视口之间的关系

关系说不太清,布局视口就是默认980px做的网页,视觉就是我们在设备上能看到的内容,可以缩放,理想就是可以在设备上一次性看到整个网页,不能缩放。

实战代码和效果图

html

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>仿淘宝移动端首页-self</title>
  8. <link rel="stylesheet" href="./css/reset.css">
  9. <link rel="stylesheet" href="./css/header.css">
  10. <link rel="stylesheet" href="./font_icon/iconfont.css">
  11. <link rel="stylesheet" href="./css/footer.css">
  12. <link rel="stylesheet" href="./css/main.css">
  13. </head>
  14. <body>
  15. <!-- 头部 -->
  16. <header>
  17. <!-- 顶部搜索栏 -->
  18. <div class="top">
  19. <!-- logo -->
  20. <div class="logo iconfont icon-shejiaotubiao-08"></div>
  21. <!-- 搜索框 -->
  22. <div class="search">
  23. <span class="iconfont icon-fangdajing"></span>
  24. <span>寻找宝贝店铺</span>
  25. </div>
  26. </div>
  27. <!-- 轮播图 -->
  28. <div class="slider"><img src="./images/banner/banner1.jpg" alt=""></div>
  29. <!-- 导航 -->
  30. <ul class="nav">
  31. <li class="item">
  32. <a href=""><img src="images/nav/nav6.png" alt="" /></a>
  33. <a href="">天猫新品</a>
  34. </li>
  35. <li class="item">
  36. <a href=""><img src="images/nav/nav3.png" alt="" /></a>
  37. <a href="">今日爆款</a>
  38. </li>
  39. <li class="item">
  40. <a href=""><img src="images/nav/nav1.png" alt="" /></a>
  41. <a href="">天猫超市</a>
  42. </li>
  43. <li class="item">
  44. <a href=""><img src="images/nav/nav2.png" alt="" /></a>
  45. <a href="">充值中心</a>
  46. </li>
  47. <li class="item">
  48. <a href=""><img src="images/nav/nav5.png" alt="" /></a>
  49. <a href="">机票酒店</a>
  50. </li>
  51. <li class="item">
  52. <a href=""><img src="images/nav/nav8.png" alt="" /></a>
  53. <a href="">金币庄园</a>
  54. </li>
  55. <li class="item">
  56. <a href=""><img src="images/nav/nav7.png" alt="" /></a>
  57. <a href="">阿里拍卖</a>
  58. </li>
  59. <li class="item">
  60. <a href=""><img src="images/nav/nav4.png" alt="" /></a>
  61. <a href="">分类</a>
  62. </li>
  63. <li class="item">
  64. <a href=""><img src="images/nav/nav7.png" alt="" /></a>
  65. <a href="">阿里拍卖</a>
  66. </li>
  67. <li class="item">
  68. <a href=""><img src="images/nav/nav4.png" alt="" /></a>
  69. <a href="">分类</a>
  70. </li>
  71. </ul>
  72. </header>
  73. <!-- 主体 -->
  74. <main style="height: 1600px">
  75. <!-- 1. 聚划算 -->
  76. <div class="top">
  77. <div class="item jhs">
  78. <div class="box">
  79. <h3 class="title">聚划算</h3>
  80. <div class="desc">
  81. <h4>品牌折扣</h4>
  82. <img src="images/items/item1.png" alt="" />
  83. </div>
  84. </div>
  85. <div class="box">
  86. <!-- 用实体空格表示占位符 -->
  87. <h3 class="title">&nbsp;</h3>
  88. <div class="desc">
  89. <h4>划算好货</h4>
  90. <img src="images/items/item2.png" alt="" />
  91. </div>
  92. </div>
  93. <div class="box">
  94. <h3 class="title">淘抢购</h3>
  95. <div class="desc">
  96. <h4>限时半价</h4>
  97. <img src="images/items/item3.png" alt="" />
  98. </div>
  99. </div>
  100. <div class="box">
  101. <h3 class="title">天天特价</h3>
  102. <div class="desc">
  103. <h4>9.9包邮</h4>
  104. <img src="images/items/item4.png" alt="" />
  105. </div>
  106. </div>
  107. </div>
  108. <div class="item right">
  109. <div class="box">
  110. <h3 class="title">淘宝直播 <span class="tag" style="background-color: red">LIVE</span></h3>
  111. <div class="detail">
  112. <div class="left">
  113. <span class="title">好物传送门</span>
  114. <img src="images/items/item5.png" alt="" />
  115. </div>
  116. <div class="right">
  117. <img src="images/items/item6.png" alt="" />
  118. </div>
  119. </div>
  120. </div>
  121. <div class="box">
  122. <h3 class="title">有好货&nbsp;<span class="tag" style="background-color: skyblue">品质好物</span></h3>
  123. <div class="detail">
  124. <div class="left">
  125. <span class="title" style="color: skyblue">全民口碑推荐</span>
  126. <img src="images/items/item7.png" alt="" />
  127. </div>
  128. <div class="right">
  129. <img src="images/items/item21.png" alt="" />
  130. </div>
  131. </div>
  132. </div>
  133. </div>
  134. <div class="item right">
  135. <div class="box">
  136. <h3 class="title">每日好店 <span class="tag" style="background-color: orange">精选</span></h3>
  137. <div class="detail">
  138. <div class="left">
  139. <span class="title">深挖藏的店</span>
  140. <img src="images/items/item9.png" alt="" />
  141. </div>
  142. <div class="right">
  143. <img src="images/items/item10.png" alt="" />
  144. </div>
  145. </div>
  146. </div>
  147. </div>
  148. <div class="item right">
  149. <div class="box">
  150. <h3 class="title">哇哦视频<span class="tag" style="background-color: orange">亲测</span></h3>
  151. <div class="detail">
  152. <div class="left">
  153. <span class="title">粉丝都爱看</span>
  154. <img src="images/items/item11.png" alt="" />
  155. </div>
  156. <div class="right">
  157. <img src="images/items/item12.png" alt="" />
  158. </div>
  159. </div>
  160. </div>
  161. </div>
  162. <!-- 底部滚动显示文本 -->
  163. <div class="item footer">
  164. <div class="title">淘宝头条</div>
  165. <div class="content">
  166. <span class="type">评测</span>
  167. <span style="font-size: larger">五款最强的防******</span>
  168. </div>
  169. </div>
  170. </div>
  171. <!-- 2. 商品列表 -->
  172. <div class="list"></div>
  173. </main>
  174. <!-- 尾部 -->
  175. <footer>
  176. <div class="item active">
  177. <a href="" class="iconfont icon-shejiaotubiao-44"></a>
  178. </div>
  179. <div class="item">
  180. <a href="" class="iconfont icon-gouwuche"></a>
  181. <a href="">购物车</a>
  182. </div>
  183. <div class="item">
  184. <a href="" class="iconfont icon-wodetaobao"></a>
  185. <a href="">我的淘宝</a>
  186. </div>
  187. </footer>
  188. </body>
  189. </html>

css

  1. /* 样式重置 */
  2. * {
  3. margin: 0;
  4. padding: 0;
  5. box-sizing: border-box;
  6. }
  7. /* 链接 */
  8. a {
  9. text-decoration: none;
  10. color: #555;
  11. }
  12. /* 列表 */
  13. li {
  14. list-style: none;
  15. }
  16. :root {
  17. font-size: calc(100vw / 3.75);
  18. }
  19. body {
  20. font-size: 0.12rem;
  21. color: #333;
  22. max-width: 700px;
  23. min-width: 320px;
  24. margin: auto;
  25. background-color: #f4f4f4;
  26. }
  27. @media screen and (max-width: 320px) {
  28. :root {
  29. font-size: 85px;
  30. }
  31. }
  32. @media screen and (min-width: 640px) {
  33. :root {
  34. font-size: 170px;
  35. }
  36. }
  37. /* 头部 */
  38. header {
  39. position: relative;
  40. }
  41. /* 头部-->顶部 */
  42. header .top {
  43. /* position: fixed;
  44. display: grid;
  45. grid-template-columns: .3rem 1fr;
  46. width: 100vw;
  47. top: 0;
  48. left: 0;
  49. right: 0;
  50. background-color: #fd7c52;
  51. place-items: center;
  52. padding: .05rem;
  53. z-index: 99; */
  54. width: 100vw;
  55. background-color: coral;
  56. position: fixed;
  57. top: 0;
  58. left: 0;
  59. right: 0;
  60. display: grid;
  61. grid-template-columns: 0.35rem 1fr;
  62. padding: 0.03rem;
  63. place-items: center;
  64. /* 调整显示层级 */
  65. z-index: 99;
  66. }
  67. /* logo */
  68. header .logo {
  69. font-size: .3rem;
  70. color: #fff;
  71. margin-left: .01rem;
  72. }
  73. /* 搜索框 */
  74. header .search {
  75. color: #fff;
  76. background-color: #fd3e05;
  77. width: 95%;
  78. text-align: center;
  79. border-radius: .05rem;
  80. padding: .03rem;
  81. }
  82. /* 轮播图 */
  83. header .slider {
  84. position: absolute;
  85. height: 1rem;
  86. top: .37rem;
  87. }
  88. header .slider img ,
  89. header .nav img {
  90. width: 100%;
  91. }
  92. /* 导航栏 */
  93. header .nav {
  94. position: absolute;
  95. top: calc(.4rem + 1rem + .1rem);
  96. display: grid;
  97. grid-template-columns: repeat(5 , 1fr);
  98. place-items: center;
  99. place-content: center;
  100. background-color: #fff;
  101. padding-top: .1rem;
  102. }
  103. header .nav .item {
  104. display: grid;
  105. padding: .05rem;
  106. place-items: center;
  107. }
  108. header .nav .item a {
  109. padding: 0 0.05rem;
  110. }
  111. main {
  112. position: relative;
  113. top: calc(0.37rem + 1.25rem + 1.5rem);
  114. padding: 0.1rem;
  115. }
  116. main img {
  117. width: 100%;
  118. height: 100%;
  119. }
  120. main .top {
  121. background-color: #fff;
  122. border-radius: 0.1rem;
  123. min-height: 3rem;
  124. /* 3行2列 */
  125. display: grid;
  126. grid-template-columns: repeat(2, 1fr);
  127. gap: 0.1rem;
  128. padding: 0.1rem;
  129. }
  130. /* 最后一行,跨2列 */
  131. main .top .item:last-of-type {
  132. grid-column: span 2;
  133. /* background-color: yellow; */
  134. }
  135. /* 左上角的聚划算 */
  136. main .top .item.jhs {
  137. display: grid;
  138. grid-template-columns: repeat(2, 1fr);
  139. gap: 0.1rem;
  140. }
  141. main .top .item.jhs .box {
  142. display: grid;
  143. gap: 0.1rem;
  144. }
  145. main .top .item.jhs .box .desc {
  146. display: grid;
  147. background-color: rgb(243, 235, 236);
  148. border-radius: 0.1rem;
  149. padding: 0.1rem;
  150. }
  151. /* 右侧, 上下二组 */
  152. main .top .item.right {
  153. display: grid;
  154. gap: 0.1rem;
  155. }
  156. main .top .item.right .box {
  157. display: grid;
  158. }
  159. main .top .item.right .box .title {
  160. grid-column: span 2;
  161. }
  162. main .top .item.right .box .title .tag {
  163. color: #fff;
  164. font-weight: normal;
  165. padding: 1px;
  166. border-radius: 0.05rem;
  167. font-size: smaller;
  168. }
  169. main .top .item.right .box .detail {
  170. display: grid;
  171. grid-template-columns: repeat(2, 1fr);
  172. }
  173. main .top .item.right .box .detail .left {
  174. display: grid;
  175. }
  176. /* 底部公告 */
  177. main .item.footer {
  178. display: grid;
  179. grid-template-columns: 0.6rem 1fr;
  180. padding: 0.1rem 0;
  181. }
  182. main .item.footer .type {
  183. background-color: rgb(238, 202, 206);
  184. color: darkorange;
  185. padding: 2px 5px;
  186. border-radius: 3px;
  187. }
  188. main .item.footer .title {
  189. font-size: larger;
  190. font-weight: bolder;
  191. }footer {
  192. width: 100vw;
  193. height: 0.46rem;
  194. background-color: #fff;
  195. position: fixed;
  196. bottom: 0;
  197. left: 0;
  198. right: 0;
  199. display: grid;
  200. grid-template-columns: repeat(3, 1fr);
  201. place-items: center;
  202. }
  203. footer .item {
  204. display: grid;
  205. place-items: center;
  206. }
  207. footer .item .iconfont {
  208. font-size: 0.2rem;
  209. }
  210. footer .item.active .iconfont {
  211. font-size: 0.36rem;
  212. color: coral;
  213. }
声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议