Blogger Information
Blog 18
fans 0
comment 0
visits 7888
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
移动端布局思路与三种视口的关系 ,仿淘宝首页基本布局
只如初见
Original
317 people have browsed it

移动端布局思路与三种视口的关系

  1. 三种视口
  2. 概念理解:
  3. 布局视图: 980px width
  4. 视觉视图: 375px device-width
  5. 修改布局视图: width = device-width, 布局视图等于视觉视图
  6. initial-scale=1.0, 初始化时,布局视图/视觉视图=1: 理想视图
  7. 页面设置
  8. 1. 布局视图 = 视觉视图: width = device-width
  9. 2. 理想视图 = 视觉视图: initial-scale=1.0
  10. 说明:
  11. px不能在移动端布局直接使用,因为px是固定值,移动端的显示效果和设置尺寸有关
  12. 主流解决方案使用: rem + vw
  13. 默认1rem = 16px
  14. 为了计算方便和布局, 通常将1rem = 100px
  15. 基础代码:
  16. html{
  17. /* font-size: 100px; */
  18. font-size: calc(100vw / 3.75);
  19. /* 100px = 100px */
  20. }
  21. body {
  22. /* 在body中将font-size还原成浏览器默认值 12px , 否则后面的em就全错了 */
  23. /* font-size: 12px; */
  24. font-size: 0.12rem;
  25. }
  26. /* 限制一下手机上最小和最大的字号 */
  27. @media screen and (max-width: 320px) {
  28. html{
  29. font-size: 85px;
  30. }
  31. }
  32. @media screen and (min-width: 640px) {
  33. html{
  34. font-size: 170px;
  35. }
  36. }

仿淘宝首页基本布局

新加代码

  1. #头部,底部,基本按照老师的原样敲了一遍,里面有些自己的改动,去掉了内容的绝对定制,改成了一直用padding顶下来显示,下面是我自己新加的产品列表排版
  2. <!-- 产品列表 -->
  3. <div class="plist">
  4. <div class="plist_t"><img src="images/xihuan.png" /></div>
  5. <div class="plist_c">
  6. <div>
  7. <a href="#">
  8. <img src="images/p_list.jpg" />
  9. <p>吃牛排的刀叉三件套西餐套装餐具刀勺全套两家用盘西餐具盘子儿童</p>
  10. <div><span>¥12.9</span><span>2000+人已购买</span></div>
  11. </a>
  12. </div>
  13. <div>
  14. <a href="#">
  15. <img src="images/p_list.jpg" />
  16. <p>吃牛排的刀叉三件套西餐套装餐具刀勺全套两家用盘西餐具盘子儿童</p>
  17. <div><span>¥12.9</span><span>2000+人已购买</span></div>
  18. </a>
  19. </div>
  20. <div>
  21. <a href="#">
  22. <img src="images/p_list.jpg" />
  23. <p>吃牛排的刀叉三件套西餐套装餐具刀勺全套两家用盘西餐具盘子儿童</p>
  24. <div><span>¥12.9</span><span>2000+人已购买</span></div>
  25. </a>
  26. </div>
  27. <div>
  28. <a href="#">
  29. <img src="images/p_list.jpg" />
  30. <p>吃牛排的刀叉三件套西餐套装餐具刀勺全套两家用盘西餐具盘子儿童</p>
  31. <div><span>¥12.9</span><span>2000+人已购买</span></div>
  32. </a>
  33. </div>
  34. </div>
  35. </div>
  36. css样式
  37. main {
  38. padding-bottom: 0.5rem;
  39. }
  40. .plist {
  41. padding: 0.2rem;
  42. }
  43. .plist_t {
  44. text-align: center;
  45. margin-bottom: 0.25rem;
  46. }
  47. .plist_t img {
  48. width: 50%;
  49. height: auto;
  50. }
  51. .plist_c {
  52. display: grid;
  53. grid-template-columns: repeat(2, 1fr);
  54. gap: 0.1rem;
  55. grid-auto-rows: auto;
  56. }
  57. .plist_c > div {
  58. border-radius: 0.05rem;
  59. background-color: #fff;
  60. }
  61. .plist_c img {
  62. width: 100%;
  63. height: 100%;
  64. border-top-left-radius: 0.05rem;
  65. border-top-right-radius: 0.05rem;
  66. }
  67. .plist_c > div > a > p {
  68. margin: 0.06rem 0.1rem;
  69. height: 0.32rem;
  70. line-height: 0.16rem;
  71. overflow: hidden;
  72. }
  73. .plist_c > div > a > div {
  74. padding: 0 0.1rem 0.1rem;
  75. }
  76. .plist_c > div > a > div span:first-child {
  77. color: red;
  78. margin-right: 0.1rem;
  79. }

效果图

明天继续其它排版效果
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!