Blogger Information
Blog 33
fans 0
comment 0
visits 17097
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
三种视口之间的关系与移动端布局的基本思路,实战手机页面的基本整体架构:页眉,页脚,主体
lucaslwk
Original
599 people have browsed it

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

一.三种视口之间的关系

1.视口

浏览器显示页面内容的屏幕区域,可视窗口 viewport

2.布局视口

宽度 width,无关设备,通常默认 980px,移动端左右滑动查看全部

3.视觉视口

宽度 device-width,设备相关,手机屏幕可见部分,移动端缩放查看全部

4.理想视口

不必缩放可见全部,width=device-width

二.移动端布局的基本思路

1.设置视口属性

  1. <meta name="viewport" content="width=device-width, initial-scale=1.0" />

width=device-width,设置布局视口=视觉视口
inintial-scale,设置视觉视口=理想视口

2.设置 rem 值

主流解决方案:rem+vw
px 与设备相关,不可用!需要将页面中出现的 px 全部转为 rem(媒体查询设置字体大小时除外)
以 iPhone6/11 屏幕宽度(375px)为基准
1vw=3.75px
为方便计算,将 1rem 设置为 100px
100px=100vw/1vw=100vw/(375/100)=100vw/3.75

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

3.body 中将 font-size 还原成浏览器默认值 16px

推荐使用 vscode 插件’px to rem & rpx’自动将 px 转为 rem

  1. body {
  2. font-size: 0.16rem;
  3. }

4.(可选)通过媒体查询限制手机上最小和最大的字号

  1. /* 最小的字号,宽度小于等于320px采用的样式 */
  2. @media screen and (max-width: 320px) {
  3. :root {
  4. font-size: 85px;
  5. }
  6. }
  7. /* 最大的字号,宽度大于等于640px采用的样式 */
  8. @media screen and (min-width: 640px) {
  9. :root {
  10. font-size: 170px;
  11. }
  12. }

二.实战手机页面的基本整体架构:页眉,页脚,主体

实现效果

html 部分

  1. <div class="head">
  2. <div class="search">
  3. <div class="logo iconfont icon-taobao" icon-taobao></div>
  4. <div class="button">
  5. <span class="iconfont icon-sousuo"></span>
  6. <span>寻找宝贝店铺</span>
  7. </div>
  8. </div>
  9. <div class="banner"><img src="image/1.jpg" alt="" /></div>
  10. <div class="nav">
  11. <div class="item">
  12. <span class="img"><img src="image/2.png" alt="" /></span>
  13. <span>天猫新品</span>
  14. </div>
  15. <div class="item">
  16. <span class="img"><img src="image/2.png" alt="" /></span>
  17. <span>天猫新品</span>
  18. </div>
  19. <div class="item">
  20. <span class="img"><img src="image/2.png" alt="" /></span>
  21. <span>天猫新品</span>
  22. </div>
  23. <div class="item">
  24. <span class="img"><img src="image/2.png" alt="" /></span>
  25. <span>天猫新品</span>
  26. </div>
  27. <div class="item">
  28. <span class="img"><img src="image/2.png" alt="" /></span>
  29. <span>天猫新品</span>
  30. </div>
  31. <div class="item">
  32. <span class="img"><img src="image/2.png" alt="" /></span>
  33. <span>天猫新品</span>
  34. </div>
  35. <div class="item">
  36. <span class="img"><img src="image/2.png" alt="" /></span>
  37. <span>天猫新品</span>
  38. </div>
  39. <div class="item">
  40. <span class="img"><img src="image/2.png" alt="" /></span>
  41. <span>天猫新品</span>
  42. </div>
  43. <div class="item">
  44. <span class="img"><img src="image/2.png" alt="" /></span>
  45. <span>天猫新品</span>
  46. </div>
  47. <div class="item">
  48. <span class="img"><img src="image/2.png" alt="" /></span>
  49. <span>天猫新品</span>
  50. </div>
  51. </div>
  52. </div>
  53. <div class="main" style="height: 1000px">asdsad</div>
  54. <div class="foot">
  55. <div class="logo iconfont icon-taobao"></div>
  56. <div class="buy button">
  57. <span class="iconfont icon-gouwuchekong"></span>
  58. <span>购物车</span>
  59. </div>
  60. <div class="my button">
  61. <span class="iconfont icon-zhanghu"></span>
  62. <span>我的淘宝</span>
  63. </div>
  64. </div>
  1. /* 搜索栏部分 */
  2. .head .search {
  3. display: flex;
  4. place-items: center;
  5. place-content: space-between;
  6. background-color: rgb(255, 133, 42);
  7. padding: 0.07rem;
  8. position: fixed;
  9. top: 0;
  10. right: 0;
  11. left: 0;
  12. z-index: 99;
  13. }
  14. .head .search .logo {
  15. font-size: 0.24rem;
  16. font-weight: lighter;
  17. color: white;
  18. margin: 0 5px;
  19. }
  20. .head .search .button {
  21. display: flex;
  22. place-items: center;
  23. place-content: center;
  24. height: 0.3rem;
  25. width: 3.2rem;
  26. font-size: 0.16rem;
  27. color: white;
  28. background-color: rgb(255, 78, 34);
  29. border-radius: 0.05rem;
  30. }
  31. /* 录播图部分 */
  32. .head .banner img {
  33. position: absolute;
  34. top: 0.44rem;
  35. width: 3.75rem;
  36. }
  37. /* 导航部分 */
  38. .head .nav {
  39. position: absolute;
  40. top: calc(0.44rem + 1.1733rem);
  41. background-color: white;
  42. width: 3.75rem;
  43. display: grid;
  44. grid-template-columns: repeat(5, 1fr);
  45. padding-bottom: 0.1rem;
  46. }
  47. .head .nav .item {
  48. display: grid;
  49. padding: 0.05rem;
  50. margin: 0.05rem;
  51. place-content: center;
  52. place-items: center;
  53. font-size: 0.11rem;
  54. }
  55. .head .nav .item .img img {
  56. width: 0.48rem;
  57. }
  58. /*底部*/
  59. .foot {
  60. display: grid;
  61. grid-template-columns: repeat(3, 1fr);
  62. padding: 0.07rem;
  63. position: fixed;
  64. bottom: 0;
  65. right: 0;
  66. left: 0;
  67. background-color: white;
  68. z-index: 99;
  69. }
  70. .foot .logo {
  71. place-self: center;
  72. width: 0.36rem;
  73. height: 0.36rem;
  74. background-color: rgb(255, 133, 42);
  75. border-radius: 50%;
  76. font-size: 0.33rem;
  77. color: white;
  78. }
  79. .foot .button {
  80. display: grid;
  81. place-content: center;
  82. place-items: center;
  83. font-size: 0.1rem;
  84. }
  85. .foot .button .iconfont {
  86. font-size: 0.2rem;
  87. }
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