Blogger Information
Blog 21
fans 0
comment 0
visits 10047
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
1028 使用Grid / Flex , 编写淘宝网PC端首页布局
放手去爱
Original
472 people have browsed it
  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. <!-- 视口: viewport ; 布局视口宽度:width=device-width ;不需要缩放,因为当前处于理想视口状态 initial-scale=1.0 -->
  7. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  8. <title>仿淘宝移动端首页布局顶部页眉</title>
  9. <style>
  10. html {
  11. /* 电脑端写法
  12. html{font-size:100px;}
  13. */
  14. /* 手机端 动态计算rem */
  15. font-size: calc(100vw / 3.75px);
  16. }
  17. </style>
  18. </head>
  19. <body>
  20. <!--移动端的布局单位三个问题?
  21. 1.为什么用rem ?因为rem = html.font-size 而html 一个页面只有一个,所以用rem 具有唯一性
  22. 所以可以确保,在页面的任何地方引用rem,可确保总是计算出一个确定的值
  23. 1rem = 100px ;是为了计算方便
  24. 为什么不能将rem 写死。
  25. 默认情况下 rem 应该是一个常量 html.font-size
  26. 使用rem + vw 实现动态的 rem
  27. 三个视口
  28. 1. 布局视口 ,面向开发者,与设备无关
  29. 2. 视觉视口:与具体的硬件相关,用户看到的手机屏幕大小 `device-width `
  30. 3. 理想视口:抽像的 `width = device-width` `initial-scale=1.0`原比列显示
  31. -->
  32. <!-- rem + vw
  33. * 1. 1vw = ?
  34. 苹果SE 为例 = 375px = 100vw ; 1vw = 1 / 100vw = 1 / 375px = 3.75px
  35. 375px : 1vw = 3.75px
  36. *2. 1rem = ?
  37. *3. DPR : DPR 设备像素比 = 设备像素 / 布局像素
  38. 苹果SE 为例 : DPR 2 = 750px / 355px
  39. 布局时用375px ,在设备中显示时,可以根据DPR 换算成物理像素
  40. -->
  41. <!-- 头部 -->
  42. <style>
  43. * {
  44. margin: 0;
  45. padding: 0;
  46. box-sizing: border-box;
  47. }
  48. a {
  49. text-decoration: none;
  50. color: black;
  51. }
  52. html {
  53. /* font-size: 100px; */
  54. font-size: calc(100vw / 3.75);
  55. }
  56. body {
  57. font-size: 0.13rem;
  58. color: black;
  59. margin: auto;
  60. padding: 0 0.15rem;
  61. }
  62. body img {
  63. width: 100%;
  64. }
  65. @media (max-width: 320px) {
  66. html {
  67. font-size: 85px;
  68. }
  69. }
  70. @media (min-width: 640px) {
  71. html {
  72. font-size: 160px;
  73. }
  74. }
  75. header {
  76. display: grid;
  77. grid-template-columns: 0.58rem 1fr 0.33rem;
  78. grid-auto-rows: 0.5rem;
  79. place-items: center;
  80. gap: 10px;
  81. }
  82. header a.logo {
  83. padding: 0.1rem;
  84. background-color: bisque;
  85. }
  86. header > a.search {
  87. width: 100%;
  88. height: 0.3rem;
  89. border-radius: 0.1rem;
  90. border: 2px solid #e78514;
  91. /* grid: 整体 flex: 细节 */
  92. display: flex;
  93. place-content: space-between;
  94. place-items: center;
  95. }
  96. header > a.search > span:first-of-type {
  97. padding-left: 0.1rem;
  98. }
  99. header > a.search > span:last-of-type {
  100. background: linear-gradient(to left, #e78514, #f3c992);
  101. color: aliceblue;
  102. padding: 0.05rem 0.15rem;
  103. border-radius: 0.02rem;
  104. }
  105. header > a.iconfont {
  106. color: #f0ede9;
  107. font-size: 0.14rem;
  108. background-color: #e78514;
  109. padding: 0.02rem;
  110. }
  111. main {
  112. background-color: burlywood;
  113. main-height: 2000px;
  114. position: relative;
  115. top: 50px;
  116. }
  117. footer {
  118. position: fixed;
  119. bottom: 0;
  120. background: wheat;
  121. }
  122. </style>
  123. <header>
  124. <!-- logo -->
  125. <a href="http://m.taobao.com" class="logo"
  126. ><img src="images/logo.png" alt="LOGO"
  127. /></a>
  128. <!-- 搜索 -->
  129. <a href="" class="search"><span>导店内宝贝</span><span>搜索</span></a>
  130. <!-- 签到 -->
  131. <a href="" class="iconfont icon-qiandao-xuanzhong">签到</a>
  132. </header>
  133. <!-- 内容 -->
  134. <main>内容</main>
  135. <!-- 底部 -->
  136. <footer>页脚</footer>
  137. </body>
  138. </html>

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