Blogger Information
Blog 26
fans 0
comment 1
visits 10541
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
使用Grid / Flex , 编写淘宝网PC端首页布局
P粉751989631
Original
360 people have browsed it

使用Grid / Flex , 编写淘宝网PC端首页布局

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>淘宝PC端布局框架</title>
  8. <link rel="stylesheet" href="css/csspc.css" />
  9. </head>
  10. <body>
  11. <div class="wrap">
  12. <!-- (1)头部 -->
  13. <header>
  14. <!-- 1.顶部导航 -->
  15. <div class="top">
  16. <div class="content"></div>
  17. </div>
  18. <!-- 2.快速入口 -->
  19. <div class="entry">
  20. <div class="content">
  21. <div class="item logo"></div>
  22. <div class="item"></div>
  23. <div class="item"></div>
  24. <div class="item"></div>
  25. <div class="item"></div>
  26. <div class="item"></div>
  27. </div>
  28. </div>
  29. </header>
  30. <!-- (2) 主体 -->
  31. <main>
  32. <!-- 1. 搜索框 -->
  33. <div class="search">
  34. <div class="item logo"></div>
  35. <div class="item input"></div>
  36. <div class="item ewm"></div>
  37. </div>
  38. <!-- 2. 导航区 -->
  39. <div class="navs">
  40. <!-- 1. 左侧分类 -->
  41. <div class="cate"></div>
  42. <!-- 2. 在侧轮播图与用户信息 -->
  43. <div class="user">
  44. <!-- 1. 顶部导航 -->
  45. <div class="user-top"></div>
  46. <!-- 左侧轮播图 -->
  47. <div class="slider"></div>
  48. <!-- 右侧用户信息 -->
  49. <div class="user-info"></div>
  50. </div>
  51. </div>
  52. <!-- 3. 标题区 -->
  53. <div class="title">
  54. <h2>猜你喜欢</h2>
  55. <div class="tag">个性推荐</div>
  56. </div>
  57. <!-- 4. 商品列表 -->
  58. <div class="list">
  59. <div class="item">
  60. <a href=""><img src="" alt="" /></a>
  61. <div class="detail">
  62. <div class="desc">商品描述商品描述商品描述商品描述</div>
  63. <div class="price">159</div>
  64. </div>
  65. </div>
  66. <div class="item">
  67. <a href=""><img src="" alt="" /></a>
  68. <div class="detail">
  69. <div class="desc">商品描述商品描述商品描述商品描述</div>
  70. <div class="price">159</div>
  71. </div>
  72. </div>
  73. <div class="item">
  74. <a href=""><img src="" alt="" /></a>
  75. <div class="detail">
  76. <div class="desc">商品描述商品描述商品描述商品描述</div>
  77. <div class="price">159</div>
  78. </div>
  79. </div>
  80. <div class="item">
  81. <a href=""><img src="" alt="" /></a>
  82. <div class="detail">
  83. <div class="desc">商品描述商品描述商品描述商品描述</div>
  84. <div class="price">159</div>
  85. </div>
  86. </div>
  87. <div class="item">
  88. <a href=""><img src="" alt="" /></a>
  89. <div class="detail">
  90. <div class="desc">商品描述商品描述商品描述商品描述</div>
  91. <div class="price">159</div>
  92. </div>
  93. </div>
  94. <div class="item">
  95. <a href=""><img src="" alt="" /></a>
  96. <div class="detail">
  97. <div class="desc">商品描述商品描述商品描述商品描述</div>
  98. <div class="price">159</div>
  99. </div>
  100. </div>
  101. <div class="item">
  102. <a href=""><img src="" alt="" /></a>
  103. <div class="detail">
  104. <div class="desc">商品描述商品描述商品描述商品描述</div>
  105. <div class="price">159</div>
  106. </div>
  107. </div>
  108. <div class="item">
  109. <a href=""><img src="" alt="" /></a>
  110. <div class="detail">
  111. <div class="desc">商品描述商品描述商品描述商品描述</div>
  112. <div class="price">159</div>
  113. </div>
  114. </div>
  115. <div class="item">
  116. <a href=""><img src="" alt="" /></a>
  117. <div class="detail">
  118. <div class="desc">商品描述商品描述商品描述商品描述</div>
  119. <div class="price">159</div>
  120. </div>
  121. </div>
  122. <div class="item">
  123. <a href=""><img src="" alt="" /></a>
  124. <div class="detail">
  125. <div class="desc">商品描述商品描述商品描述商品描述</div>
  126. <div class="price">159</div>
  127. </div>
  128. </div>
  129. <div class="item">
  130. <a href=""><img src="" alt="" /></a>
  131. <div class="detail">
  132. <div class="desc">商品描述商品描述商品描述商品描述</div>
  133. <div class="price">159</div>
  134. </div>
  135. </div>
  136. <div class="item">
  137. <a href=""><img src="" alt="" /></a>
  138. <div class="detail">
  139. <div class="desc">商品描述商品描述商品描述商品描述</div>
  140. <div class="price">159</div>
  141. </div>
  142. </div>
  143. <div class="item">
  144. <a href=""><img src="" alt="" /></a>
  145. <div class="detail">
  146. <div class="desc">商品描述商品描述商品描述商品描述</div>
  147. <div class="price">159</div>
  148. </div>
  149. </div>
  150. <div class="item">
  151. <a href=""><img src="" alt="" /></a>
  152. <div class="detail">
  153. <div class="desc">商品描述商品描述商品描述商品描述</div>
  154. <div class="price">159</div>
  155. </div>
  156. </div>
  157. <div class="item">
  158. <a href=""><img src="images/items/item-11.webp" alt="" /></a>
  159. <div class="detail">
  160. <div class="desc">商品描述商品描述商品描述商品描述</div>
  161. <div class="price">159</div>
  162. </div>
  163. </div>
  164. <div class="item">
  165. <a href=""><img src="" alt="" /></a>
  166. <div class="detail">
  167. <div class="desc">商品描述商品描述商品描述商品描述</div>
  168. <div class="price">159</div>
  169. </div>
  170. </div>
  171. <div class="item">
  172. <a href=""><img src="" alt="" /></a>
  173. <div class="detail">
  174. <div class="desc">商品描述商品描述商品描述商品描述</div>
  175. <div class="price">159</div>
  176. </div>
  177. </div>
  178. </main>
  179. </div>
  180. </body>
  181. </html>

CSS代码:

  1. * {
  2. margin: 0;
  3. padding: 0;
  4. box-sizing: border-box;
  5. }
  6. body {
  7. min-height: 2000px;
  8. }
  9. /* 头部,导航 */
  10. .wrap header .top {
  11. width: 100vw;
  12. height: 36px;
  13. background-color: yellow;
  14. }
  15. .wrop header .top .content {
  16. width: 1190px;
  17. height: inherit;
  18. background-color: wheat;
  19. margin: auto;
  20. }
  21. /* 头部:快速入口 */
  22. .wrap header .entry {
  23. width: 100px;
  24. padding: 15px;
  25. }
  26. .wrap header .entry .content {
  27. max-width: 1190px;
  28. min-width: 940px;
  29. height: inherit;
  30. background-color: cyan;
  31. margin: auto;
  32. display: grid;
  33. grid-template-columns: 80px repeat(5, 1fr);
  34. grid-auto-rows: 80px;
  35. gap: 16px;
  36. padding: 10px;
  37. }
  38. .wrap header .entry .content .item {
  39. background-color: lightcyan;
  40. border-radius: 15px;
  41. }
  42. /* 主体 */
  43. .wrap main {
  44. max-width: 1190px;
  45. min-width: 940px;
  46. min-height: 1000px;
  47. margin: 20px auto;
  48. padding: 20px;
  49. background-color: lightgreen;
  50. }
  51. /* 搜索框 */
  52. .wrap main .search {
  53. height: 88px;
  54. display: grid;
  55. grid-template-columns: 190px 1fr 90px;
  56. gap: 10px;
  57. /* 粘性定位 */
  58. position: sticky;
  59. top: 0;
  60. }
  61. .wrap main .search .item {
  62. background-color: lightcoral;
  63. }
  64. /* 主体导航区 */
  65. main .navs {
  66. height: 423px;
  67. margin: 20px 0;
  68. display: grid;
  69. grid-template-columns: 270px 1fr;
  70. gap: 10px;
  71. }
  72. main .navs > * {
  73. background-color: lightskyblue;
  74. }
  75. main .navs > .user {
  76. display: grid;
  77. /* 2行2列 */
  78. grid-template-columns: 564px 1fr;
  79. grid-template-rows: 42px 1fr;
  80. gap: 10px;
  81. }
  82. main .navs > .user > * {
  83. background-color: lightcyan;
  84. }
  85. main .navs > .user .user-top {
  86. grid-column: span 2;
  87. }
  88. /* 主体标题区 */
  89. main .title {
  90. background-color: lightcyan;
  91. display: flex;
  92. place-items: center;
  93. }
  94. main .title .tag {
  95. background: linear-gradient(to left, orangered, orange);
  96. color: white;
  97. border-radius: 5px;
  98. padding: 0 5px;
  99. margin-left: 6px;
  100. cursor: default;
  101. }
  102. /* 主体: 商品列表 */
  103. main .list {
  104. margin: 20px 0;
  105. display: grid;
  106. grid-template-columns: repeat(3, 1fr);
  107. grid-auto-rows: 172px;
  108. gap: 10px;
  109. }
  110. main .list > .item {
  111. background-color: lightcyan;
  112. border-radius: 6px;
  113. display: grid;
  114. grid-template-columns: 150px 1fr;
  115. gap: 10px;
  116. padding: 10px;
  117. }
  118. main .list > .item > * {
  119. background-color: wheat;
  120. border-radius: 6px;
  121. }
  122. main .list > .item img {
  123. width: 100%;
  124. border-radius: 6px;
  125. }
  126. main .list .item .detail {
  127. display: grid;
  128. grid-template-rows: 1fr 25px;
  129. padding: 10px;
  130. place-content: space-between;
  131. }
  132. main .list .item .detail > * {
  133. background-color: aqua;
  134. }
  135. /* 媒体查询 */
  136. @media (max-width: 940px) {
  137. .wrap header .entry .content {
  138. grid-template-columns: 80px repeat(4, 1fr);
  139. }

运行结果
运行结果

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