Blogger Information
Blog 12
fans 0
comment 0
visits 5449
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
HTML 学习
。。。
Original
619 people have browsed it

HTML 学习

移动布局原理

1. 重要术语

(1) 术语

序号 名称 描述
1 像素 图像显示最小单位,PPI(像素分辨率)
2 DPR 设备像素比 = 设备像素 / CSS 像素
3 视口 可视窗口 viewport,分布局/视觉/理想三类

2. 三种视口描述

三种视口类型是人为的划分

序号 名称 描述
1 布局视口Layout viewport 设备无关, 通常默认980px,显示完整网页
2 视觉视口visual viewport 设备相关,用户手机屏幕可见部分,通过缩放查看全部
3 理想视口idea viewport 不必缩放就可查看全部,针对移动端进行布局

3. 解决方案

视口属性:<meta name="viewport" content="width=device-width, initial-scale=1.0" />

序号 属性值 描述
1 width=device-width 布局视图 = 视觉视图
2 initial-scale=1.0 视觉视图 = 理想视图

移动端布局单位很多,经典的百分比,em 等,但目前主流单位是: rem + vw,也称”rem-vw`解决方案

4. 推荐 vscode 插件

  1. 名称: px to rem & rpx,原名为cssrem
  2. 自动将px换算为rem
  3. 须在插件中设置1rem = ...px,默认为16px,通常设置为1rem=100px以方便计算

5. 操作步骤

布局前,必须先确定 1rem = ?, 1vw =?

5.1 1vw = ?

  1. 选择某款手机做为理想视口的基础,如iPhone11: 375px
  2. 100vw = 100% = 375px, 所以 1vw = 3.75px

5.2 1rem = ?

  1. 1rem 默认为游览器字号16px
  2. 推荐: 1rem = 100px
  3. 1rem不要在<html>中写死, 应该通过100vw计算出来

5.3 总结

序号 属性值 描述
1 1vw = 3.75px iPhone6/11屏幕宽度为基准
2 1rem = 100vw / 3.75 1rem = 100px, 方便计算

淘宝页面仿写

1. 布局思路

分为 header main footer 三个部分

header 包含 顶部固定 搜索;首页轮播图 ;导航

main 包含 商品推广 ;商品列表

footer 包含 底部固定 导航

2. 效果演示

效果演示1

3 代码

HTML

  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  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>仿淘宝移动端首页</title>
  8. <link rel="stylesheet" href="font_icon/iconfont.css" />
  9. <link rel="stylesheet" href="css/reset.css" />
  10. <link rel="stylesheet" href="css/header.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. <div class="keys">
  24. <span class="iconfont icon-fangdajing"></span>
  25. <span>寻找宝贝店铺</span>
  26. </div>
  27. </div>
  28. </div>
  29. <!-- 轮播图 -->
  30. <div class="slider">
  31. <a href=""><img src="images/banner/banner1.jpg" alt="" /></a>
  32. </div>
  33. <!-- 导航组 -->
  34. <ul class="nav">
  35. <li class="item">
  36. <a href=""><img src="images/nav/nav6.png" alt="" /></a>
  37. <a href="">天猫新品</a>
  38. </li>
  39. <li class="item">
  40. <a href=""><img src="images/nav/nav3.png" alt="" /></a>
  41. <a href="">今日爆款</a>
  42. </li>
  43. <li class="item">
  44. <a href=""><img src="images/nav/nav1.png" alt="" /></a>
  45. <a href="">天猫超市</a>
  46. </li>
  47. <li class="item">
  48. <a href=""><img src="images/nav/nav2.png" alt="" /></a>
  49. <a href="">充值中心</a>
  50. </li>
  51. <li class="item">
  52. <a href=""><img src="images/nav/nav5.png" alt="" /></a>
  53. <a href="">机票酒店</a>
  54. </li>
  55. <li class="item">
  56. <a href=""><img src="images/nav/nav8.png" alt="" /></a>
  57. <a href="">金币庄园</a>
  58. </li>
  59. <li class="item">
  60. <a href=""><img src="images/nav/nav7.png" alt="" /></a>
  61. <a href="">阿里拍卖</a>
  62. </li>
  63. <li class="item">
  64. <a href=""><img src="images/nav/nav4.png" alt="" /></a>
  65. <a href="">分类</a>
  66. </li>
  67. <li class="item">
  68. <a href=""><img src="images/nav/nav7.png" alt="" /></a>
  69. <a href="">阿里拍卖</a>
  70. </li>
  71. <li class="item">
  72. <a href=""><img src="images/nav/nav4.png" alt="" /></a>
  73. <a href="">分类</a>
  74. </li>
  75. </ul>
  76. </header>
  77. <!-- 主体 -->
  78. <main style="height: 1600px">
  79. <!-- 1. 聚划算 -->
  80. <div class="top">
  81. <div class="item jhs">
  82. <div class="box">
  83. <h3 class="title">聚划算</h3>
  84. <div class="desc">
  85. <h4>品牌折扣</h4>
  86. <img src="images/items/item1.png" alt="" />
  87. </div>
  88. </div>
  89. <div class="box">
  90. <!-- 用实体空格表示占位符 -->
  91. <h3 class="title">&nbsp;</h3>
  92. <div class="desc">
  93. <h4>划算好货</h4>
  94. <img src="images/items/item2.png" alt="" />
  95. </div>
  96. </div>
  97. <div class="box">
  98. <h3 class="title">淘抢购</h3>
  99. <div class="desc">
  100. <h4>限时半价</h4>
  101. <img src="images/items/item3.png" alt="" />
  102. </div>
  103. </div>
  104. <div class="box">
  105. <h3 class="title">天天特价</h3>
  106. <div class="desc">
  107. <h4>9.9包邮</h4>
  108. <img src="images/items/item4.png" alt="" />
  109. </div>
  110. </div>
  111. </div>
  112. <div class="item right">
  113. <div class="box">
  114. <h3 class="title">
  115. 淘宝直播
  116. <span class="tag" style="background-color: red">LIVE</span>
  117. </h3>
  118. <div class="detail">
  119. <div class="left">
  120. <span class="title">好物传送门</span>
  121. <img src="images/items/item5.png" alt="" />
  122. </div>
  123. <div class="right">
  124. <img src="images/items/item6.png" alt="" />
  125. </div>
  126. </div>
  127. </div>
  128. <div class="box">
  129. <h3 class="title">
  130. 有好货&nbsp;<span class="tag" style="background-color: skyblue"
  131. >品质好物</span
  132. >
  133. </h3>
  134. <div class="detail">
  135. <div class="left">
  136. <span class="title" style="color: skyblue">全民口碑推荐</span>
  137. <img src="images/items/item7.png" alt="" />
  138. </div>
  139. <div class="right">
  140. <img src="images/items/item21.png" alt="" />
  141. </div>
  142. </div>
  143. </div>
  144. </div>
  145. <div class="item right">
  146. <div class="box">
  147. <h3 class="title">
  148. 每日好店
  149. <span class="tag" style="background-color: orange">精选</span>
  150. </h3>
  151. <div class="detail">
  152. <div class="left">
  153. <span class="title">深挖藏的店</span>
  154. <img src="images/items/item9.png" alt="" />
  155. </div>
  156. <div class="right">
  157. <img src="images/items/item10.png" alt="" />
  158. </div>
  159. </div>
  160. </div>
  161. </div>
  162. <div class="item right">
  163. <div class="box">
  164. <h3 class="title">
  165. 哇哦视频<span class="tag" style="background-color: orange"
  166. >亲测</span
  167. >
  168. </h3>
  169. <div class="detail">
  170. <div class="left">
  171. <span class="title">粉丝都爱看</span>
  172. <img src="images/items/item11.png" alt="" />
  173. </div>
  174. <div class="right">
  175. <img src="images/items/item12.png" alt="" />
  176. </div>
  177. </div>
  178. </div>
  179. </div>
  180. <!-- 底部滚动显示文本 -->
  181. <div class="item footer">
  182. <div class="title">淘宝头条</div>
  183. <div class="content">
  184. <span class="type">评测</span>
  185. <span style="font-size: larger">五款最强的防******</span>
  186. </div>
  187. </div>
  188. </div>
  189. <!-- 2. 商品列表 -->
  190. <div class="list">
  191. <div class="title">------ 你可能还喜欢 ------</div>
  192. <div class="unit">
  193. <div class="img">
  194. <img src="images/items/item8.webp" alt="" />
  195. </div>
  196. <div class="detail">
  197. <div class="desc">
  198. 商品描述商品描述,商品描述商品描述,商品描述商品描述,
  199. </div>
  200. <div class="price">
  201. <span class="iconfont icon-rmb"></span>
  202. <span class="price-num">89</span>
  203. <span class="num">45人已购买</span>
  204. </div>
  205. </div>
  206. </div>
  207. <div class="unit">
  208. <div class="img">
  209. <img src="images/items/item20.webp" alt="" />
  210. </div>
  211. <div class="detail">
  212. <div class="desc">
  213. 商品描述商品描述,商品描述商品描述,商品描述商品描述,
  214. </div>
  215. <div class="price">
  216. <span class="iconfont icon-rmb"></span>
  217. <span class="price-num">89</span>
  218. <span class="num">+555545人已购买</span>
  219. </div>
  220. </div>
  221. </div>
  222. <div class="unit">
  223. <div class="img">
  224. <img src="images/items/item14.webp" alt="" />
  225. </div>
  226. <div class="detail">
  227. <div class="desc">
  228. 商品描述商品描述,商品描述商品描述,商品描述商品描述,
  229. </div>
  230. <div class="price">
  231. <span class="iconfont icon-rmb"></span>
  232. <span class="price-num">89</span>
  233. <span class="num">45人已购买</span>
  234. </div>
  235. </div>
  236. </div>
  237. <div class="unit">
  238. <div class="img">
  239. <img src="images/items/item15.webp" alt="" />
  240. </div>
  241. <div class="detail">
  242. <div class="desc">
  243. 商品描述商品描述,商品描述商品描述,商品描述商品描述,
  244. </div>
  245. <div class="price">
  246. <span class="iconfont icon-rmb"></span>
  247. <span class="price-num">89</span>
  248. <span class="num">45人已购买</span>n>
  249. </div>
  250. </div>
  251. </div>
  252. <div class="unit">
  253. <div class="img">
  254. <img src="images/items/item16.webp" alt="" />
  255. </div>
  256. <div class="detail">
  257. <div class="desc">
  258. 商品描述商品描述,商品描述商品描述,商品描述商品描述,
  259. </div>
  260. <div class="price">
  261. <span class="iconfont icon-rmb"></span>
  262. <span class="price-num">89</span>
  263. <span class="num">45人已购买</span>
  264. </div>
  265. </div>
  266. </div>
  267. <div class="unit">
  268. <div class="img">
  269. <img src="images/items/item17.webp" alt="" />
  270. </div>
  271. <div class="detail">
  272. <div class="desc">
  273. 商品描述商品描述,商品描述商品描述,商品描述商品描述,
  274. </div>
  275. <div class="price">
  276. <span class="iconfont icon-rmb"></span>
  277. <span class="price-num">89</span>
  278. <span class="num">45人已购买</span>
  279. </div>
  280. </div>
  281. </div>
  282. <div class="unit">
  283. <div class="img">
  284. <img src="images/items/item18.webp" alt="" />
  285. </div>
  286. <div class="detail">
  287. <div class="desc">
  288. 商品描述商品描述,商品描述商品描述,商品描述商品描述,
  289. </div>
  290. <div class="price">
  291. <span class="iconfont icon-rmb"></span>
  292. <span class="price-num">89</span>
  293. <span class="num">45人已购买</span>
  294. </div>
  295. </div>
  296. </div>
  297. <div class="unit">
  298. <div class="img">
  299. <img src="images/items/item19.webp" alt="" />
  300. </div>
  301. <div class="detail">
  302. <div class="desc">
  303. 商品描述商品描述,商品描述商品描述,商品描述商品描述,
  304. </div>
  305. <div class="price">
  306. <span class="iconfont icon-rmb"></span>
  307. <span class="price-num">89</span>
  308. <span class="num">45人已购买</span>
  309. </div>
  310. </div>
  311. </div>
  312. <div class="unit">
  313. <div class="img">
  314. <img src="images/items/item17.webp" alt="" />
  315. </div>
  316. <div class="detail">
  317. <div class="desc">
  318. 商品描述商品描述,商品描述商品描述,商品描述商品描述,
  319. </div>
  320. <div class="price">
  321. <span class="iconfont icon-rmb"></span>
  322. <span class="price-num">89</span>
  323. <span class="num">45人已购买</span>
  324. </div>
  325. </div>
  326. </div>
  327. <div class="unit">
  328. <div class="img">
  329. <img src="images/items/item18.webp" alt="" />
  330. </div>
  331. <div class="detail">
  332. <div class="desc">
  333. 商品描述商品描述,商品描述商品描述,商品描述商品描述,
  334. </div>
  335. <div class="price">
  336. <span class="iconfont icon-rmb"></span>
  337. <span class="price-num">89</span>
  338. <span class="num">45人已购买</span>
  339. </div>
  340. </div>
  341. </div>
  342. <div class="unit">
  343. <div class="img">
  344. <img src="images/items/item19.webp" alt="" />
  345. </div>
  346. <div class="detail">
  347. <div class="desc">
  348. 商品描述商品描述,商品描述商品描述,商品描述商品描述,
  349. </div>
  350. <div class="price">
  351. <span class="iconfont icon-rmb"></span>
  352. <span class="price-num">89</span>
  353. <span class="num">45人已购买</span>
  354. </div>
  355. </div>
  356. </div>
  357. <div class="unit">
  358. <div class="img">
  359. <img src="images/items/item20.webp" alt="" />
  360. </div>
  361. <div class="detail">
  362. <div class="desc">
  363. 商品描述商品描述,商品描述商品描述,商品描述商品描述,
  364. </div>
  365. <div class="price">
  366. <span class="iconfont icon-rmb"></span>
  367. <span class="price-num">89</span>
  368. <span class="num">45人已购买</span>
  369. </div>
  370. </div>
  371. </div>
  372. </div>
  373. </main>
  374. <!-- 底部 -->
  375. <footer>
  376. <div class="item active">
  377. <a href="" class="iconfont icon-shejiaotubiao-44"></a>
  378. </div>
  379. <div class="item">
  380. <a href="" class="iconfont icon-gouwuche"></a>
  381. <a href="">购物车</a>
  382. </div>
  383. <div class="item">
  384. <a href="" class="iconfont icon-wodetaobao"></a>
  385. <a href="">我的淘宝</a>
  386. </div>
  387. </footer>
  388. </body>
  389. </html>

CSS

footer.css

  1. footer {
  2. width: 100vw;
  3. height: 0.46rem;
  4. background-color: #fff;
  5. position: fixed;
  6. bottom: 0;
  7. left: 0;
  8. right: 0;
  9. display: grid;
  10. grid-template-columns: repeat(3, 1fr);
  11. place-items: center;
  12. }
  13. footer .item {
  14. display: grid;
  15. place-items: center;
  16. }
  17. footer .item .iconfont {
  18. font-size: 0.2rem;
  19. }
  20. footer .item.active .iconfont {
  21. font-size: 0.36rem;
  22. color: coral;
  23. }

header.css

  1. header {
  2. position: relative;
  3. }
  4. header .top {
  5. width: 100vw;
  6. background-color: coral;
  7. position: fixed;
  8. top: 0;
  9. left: 0;
  10. right: 0;
  11. display: grid;
  12. grid-template-columns: 0.35rem 1fr;
  13. padding: 0.05rem;
  14. /* 调整显示层级 */
  15. z-index: 99;
  16. }
  17. header .top .logo {
  18. color: white;
  19. font-size: 0.25rem;
  20. }
  21. header .top .search {
  22. background-color: orangered;
  23. color: #eee;
  24. display: grid;
  25. place-content: center;
  26. border-radius: 0.05rem;
  27. font-size: small;
  28. }
  29. /* 轮播图,用图片代替 */
  30. header .slider {
  31. height: 1.25rem;
  32. position: absolute;
  33. top: 0.35rem;
  34. }
  35. header .slider img,
  36. header .nav img {
  37. width: 100%;
  38. height: 100%;
  39. }
  40. /* 导航组 */
  41. header .nav {
  42. background-color: #fff;
  43. position: absolute;
  44. top: calc(0.35rem + 1.25rem);
  45. display: grid;
  46. grid-template-columns: repeat(5, 1fr);
  47. font-size: 0.11rem;
  48. padding: 0.2rem 0.1rem;
  49. }
  50. header .nav .item {
  51. display: grid;
  52. place-items: center;
  53. padding: 0 0.05rem;
  54. }
  55. header .nav .item a {
  56. padding: 0 0.05rem;
  57. }

main.css

  1. main {
  2. position: relative;
  3. top: calc(0.37rem + 1.25rem + 1.5rem);
  4. padding: 0.1rem;
  5. }
  6. main img {
  7. width: 100%;
  8. height: 100%;
  9. }
  10. main .top {
  11. background-color: #fff;
  12. border-radius: 0.1rem;
  13. min-height: 3rem;
  14. /* 3行2列 */
  15. display: grid;
  16. grid-template-columns: repeat(2, 1fr);
  17. gap: 0.1rem;
  18. padding: 0.1rem;
  19. }
  20. /* 最后一行,跨2列 */
  21. main .top .item:last-of-type {
  22. grid-column: span 2;
  23. /* background-color: yellow; */
  24. }
  25. /* 左上角的聚划算 */
  26. main .top .item.jhs {
  27. display: grid;
  28. grid-template-columns: repeat(2, 1fr);
  29. gap: 0.1rem;
  30. }
  31. main .top .item.jhs .box {
  32. display: grid;
  33. gap: 0.1rem;
  34. }
  35. main .top .item.jhs .box .desc {
  36. display: grid;
  37. background-color: rgb(243, 235, 236);
  38. border-radius: 0.1rem;
  39. padding: 0.1rem;
  40. }
  41. /* 右侧, 上下二组 */
  42. main .top .item.right {
  43. display: grid;
  44. gap: 0.1rem;
  45. }
  46. main .top .item.right .box {
  47. display: grid;
  48. }
  49. main .top .item.right .box .title {
  50. grid-column: span 2;
  51. }
  52. main .top .item.right .box .title .tag {
  53. color: #fff;
  54. font-weight: normal;
  55. padding: 1px;
  56. border-radius: 0.05rem;
  57. font-size: smaller;
  58. }
  59. main .top .item.right .box .detail {
  60. display: grid;
  61. grid-template-columns: repeat(2, 1fr);
  62. }
  63. main .top .item.right .box .detail .left {
  64. display: grid;
  65. }
  66. /* 底部公告 */
  67. main .item.footer {
  68. display: grid;
  69. grid-template-columns: 0.6rem 1fr;
  70. padding: 0.1rem 0;
  71. }
  72. main .item.footer .type {
  73. background-color: rgb(238, 202, 206);
  74. color: darkorange;
  75. padding: 2px 5px;
  76. border-radius: 3px;
  77. }
  78. main .item.footer .title {
  79. font-size: larger;
  80. font-weight: bolder;
  81. }
  82. main .list {
  83. display: grid;
  84. grid-template-columns: repeat(2, 1fr);
  85. gap: 0.1rem;
  86. padding: 0.1rem 0 0.5rem 0;
  87. }
  88. main .list .title {
  89. grid-column: span 2;
  90. font-size: 0.15rem;
  91. color: coral;
  92. text-align: center;
  93. }
  94. main .list {
  95. display: grid;
  96. grid-template-columns: repeat(2, 1fr);
  97. gap: 0.1rem;
  98. padding: 0.1rem 0 0.5rem 0;
  99. }
  100. main .list .title {
  101. grid-column: span 2;
  102. font-size: 0.15rem;
  103. color: coral;
  104. text-align: center;
  105. }
  106. main .list .unit {
  107. background-color: #fff;
  108. border-radius: 0.1rem;
  109. display: grid;
  110. }
  111. main .list .unit img {
  112. border-radius: 0.1rem 0.1rem 0 0;
  113. width: 100%;
  114. height: 100%;
  115. }
  116. main .list .unit .detail {
  117. padding: 0.1rem;
  118. display: grid;
  119. gap: 0.1rem;
  120. }
  121. main .list .unit .price .iconfont {
  122. color: coral;
  123. font-size: small;
  124. }
  125. main .list .unit .price .price-num {
  126. font-size: large;
  127. color: coral;
  128. margin-right: 0.1rem;
  129. }
  130. main .list .unit .price .num {
  131. color: #ccc;
  132. }

reset.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: 750px;
  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. }
Correcting teacher:PHPzPHPz

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