博客列表 >使用 grid / flex 快速搭建出淘宝网PC端首页框架

使用 grid / flex 快速搭建出淘宝网PC端首页框架

Stonegarlic
Stonegarlic原创
2022年11月13日 18:27:43409浏览

1031作业

  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/pc.css">
  9. </head>
  10. <body>
  11. <div class="wrap">
  12. <!-- (1)头部 -->
  13. <header>
  14. <!-- 1.顶部导航 -->
  15. <div class="top">
  16. <div class="content">
  17. <span>中国大陆</span>
  18. <a href="">亲,请登录</a>
  19. <a href="">免费注册</a>
  20. <span>手机淘宝</span>
  21. <span>网页无障碍</span>
  22. <span>我的淘宝</span>
  23. <span>购物车</span>
  24. <span>收藏夹</span>
  25. <span>商品分类</span>
  26. <span>免费开店</span>
  27. <span>千牛卖家中心</span>
  28. <span>联系客服</span>
  29. </div>
  30. </div>
  31. <!-- 2.快速入口 -->
  32. <div class="entry">
  33. <div class="content">
  34. <div class="item logo"></div>
  35. <div class="item"></div>
  36. <div class="item"></div>
  37. <div class="item"></div>
  38. <div class="item"></div>
  39. <div class="item last"></div>
  40. </div>
  41. </div>
  42. </header>
  43. <!-- 主体 -->
  44. <main>
  45. <!-- (1)搜索框 -->
  46. <div class="search">
  47. <div class="item logo"></div>
  48. <div class="item input"></div>
  49. <div class="item ewm"></div>
  50. </div>
  51. <!-- (2)导航区 -->
  52. <div class="navs">
  53. <!-- 2.1 左侧分类 -->
  54. <div class="cate"></div>
  55. <!-- 2.2右侧轮播图与用户信息 -->
  56. <div class="user">
  57. <!-- 顶部导航 -->
  58. <div class="user-top"></div>
  59. <!-- 左侧轮播图 -->
  60. <div class="slider"></div>
  61. <!-- 右侧用户登录 -->
  62. <div class="user-info"></div>
  63. </div>
  64. </div>
  65. <!-- (3)标题区 -->
  66. <div class="title">
  67. <h2>猜你喜欢</h2>
  68. <div class="tag">个性推荐</div>
  69. </div>
  70. <!-- (4)商品列表 -->
  71. <div class="list">
  72. <div class="item">
  73. <a href=""><img src="https://gw.alicdn.com/bao/uploaded/i4/3984301190/O1CN01Cx5fwW1Kf45u0t6Cz_!!0-item_pic.jpg_300x300q90.jpg_.webp" alt=""></a>
  74. <div class="detail">
  75. <div class="desc">商品描述商品描述商品描述商品描述商品描述商品描述商品描述商品描述商品描述</div>
  76. <div class="price">105</div>
  77. </div>
  78. </div>
  79. <div class="item">
  80. <a href=""><img src="" alt=""></a>
  81. <div class="detail">
  82. <div class="desc">商品描述商品描述商品描述商品描述商品描述商品描述商品描述商品描述商品描述</div>
  83. <div class="price">105</div>
  84. </div>
  85. </div> <div class="item">
  86. <a href=""><img src="" alt=""></a>
  87. <div class="detail">
  88. <div class="desc">商品描述商品描述商品描述商品描述商品描述商品描述商品描述商品描述商品描述</div>
  89. <div class="price">105</div>
  90. </div>
  91. </div> <div class="item">
  92. <a href=""><img src="" alt=""></a>
  93. <div class="detail">
  94. <div class="desc">商品描述商品描述商品描述商品描述商品描述商品描述商品描述商品描述商品描述</div>
  95. <div class="price">105</div>
  96. </div>
  97. </div> <div class="item">
  98. <a href=""><img src="" alt=""></a>
  99. <div class="detail">
  100. <div class="desc">商品描述商品描述商品描述商品描述商品描述商品描述商品描述商品描述商品描述</div>
  101. <div class="price">105</div>
  102. </div>
  103. </div> <div class="item">
  104. <a href=""><img src="" alt=""></a>
  105. <div class="detail">
  106. <div class="desc">商品描述商品描述商品描述商品描述商品描述商品描述商品描述商品描述商品描述</div>
  107. <div class="price">105</div>
  108. </div>
  109. </div> <div class="item">
  110. <a href=""><img src="" alt=""></a>
  111. <div class="detail">
  112. <div class="desc">商品描述商品描述商品描述商品描述商品描述商品描述商品描述商品描述商品描述</div>
  113. <div class="price">105</div>
  114. </div>
  115. </div> <div class="item">
  116. <a href=""><img src="" alt=""></a>
  117. <div class="detail">
  118. <div class="desc">商品描述商品描述商品描述商品描述商品描述商品描述商品描述商品描述商品描述</div>
  119. <div class="price">105</div>
  120. </div>
  121. </div> <div class="item">
  122. <a href=""><img src="" alt=""></a>
  123. <div class="detail">
  124. <div class="desc">商品描述商品描述商品描述商品描述商品描述商品描述商品描述商品描述商品描述</div>
  125. <div class="price">105</div>
  126. </div>
  127. </div> <div class="item">
  128. <a href=""><img src="" alt=""></a>
  129. <div class="detail">
  130. <div class="desc">商品描述商品描述商品描述商品描述商品描述商品描述商品描述商品描述商品描述</div>
  131. <div class="price">105</div>
  132. </div>
  133. </div> <div class="item">
  134. <a href=""><img src="" alt=""></a>
  135. <div class="detail">
  136. <div class="desc">商品描述商品描述商品描述商品描述商品描述商品描述商品描述商品描述商品描述</div>
  137. <div class="price">105</div>
  138. </div>
  139. </div> <div class="item">
  140. <a href=""><img src="" alt=""></a>
  141. <div class="detail">
  142. <div class="desc">商品描述商品描述商品描述商品描述商品描述商品描述商品描述商品描述商品描述</div>
  143. <div class="price">105</div>
  144. </div>
  145. </div> <div class="item">
  146. <a href=""><img src="" alt=""></a>
  147. <div class="detail">
  148. <div class="desc">商品描述商品描述商品描述商品描述商品描述商品描述商品描述商品描述商品描述</div>
  149. <div class="price">105</div>
  150. </div>
  151. </div> <div class="item">
  152. <a href=""><img src="" alt=""></a>
  153. <div class="detail">
  154. <div class="desc">商品描述商品描述商品描述商品描述商品描述商品描述商品描述商品描述商品描述</div>
  155. <div class="price">105</div>
  156. </div>
  157. </div> <div class="item">
  158. <a href=""><img src="" alt=""></a>
  159. <div class="detail">
  160. <div class="desc">商品描述商品描述商品描述商品描述商品描述商品描述商品描述商品描述商品描述</div>
  161. <div class="price">105</div>
  162. </div>
  163. </div>
  164. </div>
  165. </main>
  166. </div>
  167. </body>
  168. </html>
  1. /* ? 样式重置 */
  2. * {
  3. margin: 0;
  4. padding: 0;
  5. box-sizing: border-box;
  6. }
  7. /* .wrap{
  8. margin: auto;
  9. } */
  10. body{
  11. /* ? 最小高度 */
  12. min-height: 2000px;
  13. /* background-color: rgb(246, 211, 123); */
  14. }
  15. /* 头部导航 */
  16. .wrap header > .top{
  17. width: 100vw;
  18. height: 35px;
  19. background-color: #f5f5f5;
  20. }
  21. .wrap header > .top > .content{
  22. width: 1190px;
  23. /* 继承父级高度 */
  24. height: inherit;
  25. background-color: aquamarine;
  26. /* 居中 */
  27. margin: auto ;
  28. display: grid;
  29. grid-auto-flow: column;
  30. place-content: center end;
  31. }
  32. .wrap header > .entry{
  33. height: 100px;
  34. /* background-color: blueviolet; */
  35. /* padding: 15px; */
  36. margin: 15px;
  37. }
  38. .wrap header .entry .content{
  39. max-width: 1190px;
  40. min-width: 940px;
  41. height: inherit;
  42. margin: auto;
  43. background-color: cadetblue;
  44. /* ?绘制6列网格 */
  45. display: grid;
  46. grid-template-columns: 80px repeat(5,1fr);
  47. /* 网格定义高度 */
  48. grid-auto-rows: 80px;
  49. /* 加上网格间距 */
  50. gap: 10px;
  51. padding: 10px;
  52. }
  53. .wrap header .entry .content .item{
  54. background-color: brown;
  55. /* border: 1px solid; */
  56. /* 边框圆角 */
  57. border-radius: 15px;
  58. }
  59. /* -------------------------------------- */
  60. /* ? 主体 */
  61. .wrap main {
  62. max-width: 1190px;
  63. min-width: 940px;
  64. min-height: 1000px;
  65. background-color:cornflowerblue;
  66. margin: 5px auto;
  67. padding: 10px;
  68. }
  69. /* ? 搜索框 */
  70. .wrap main .search{
  71. /* margin: 10px 10px; */
  72. height: 88px;
  73. display: grid;
  74. grid-template-columns: 190px 1fr 90px;
  75. gap: 10px;
  76. position: sticky;
  77. top: 0;
  78. }
  79. .wrap main .search .item{
  80. background-color:rgb(101, 243, 6);
  81. }
  82. /* 主题导航区 */
  83. main .navs{
  84. height: 423px;
  85. margin: 10px auto;
  86. display: grid;
  87. grid-template-columns: 270px 1fr;
  88. gap:10px
  89. }
  90. main .navs > .cate{
  91. background-color: antiquewhite;
  92. }
  93. main .navs .user{
  94. display: grid;
  95. grid-template-columns: 564px 1fr;
  96. grid-template-rows: 42px 1fr;
  97. gap:10px;
  98. }
  99. main .navs .user > *{
  100. background-color:aquamarine;
  101. }
  102. /* .user-top进行2列合并 */
  103. main .navs .user > .user-top{
  104. grid-column: span 2;
  105. }
  106. /* 主题标题区 */
  107. main .title{
  108. background-color: aliceblue;
  109. display: flex;
  110. place-items: center;
  111. }
  112. /* 渐变色 */
  113. main .title .tag{
  114. background: linear-gradient(to left,orangered,rgb(255, 106, 0));
  115. color: white;
  116. border-radius: 5px;
  117. padding: 0 5px;
  118. margin-left: 6px;
  119. cursor: pointer;
  120. }
  121. /* 主体:商品列表 */
  122. main .list{
  123. margin: 20px 0;
  124. display: grid;
  125. grid-template-columns: repeat(3,1fr);
  126. /* grid-template-rows: repeat(3,172px); */
  127. grid-auto-flow: 111px;
  128. grid-auto-rows: 172px;
  129. gap: 5px;
  130. }
  131. main .list .item{
  132. background-color: antiquewhite;
  133. border-radius: 5px;
  134. display: grid;
  135. grid-template-columns: 150px 1fr;
  136. gap: 10px;
  137. padding: 10px 10px;
  138. }
  139. main .list .item > *{
  140. background-color:darkgrey;
  141. border-radius: 5px;
  142. }
  143. main .list .item img{
  144. width: 100%;
  145. /* border-radius: 5px; */
  146. }
  147. main .list .item .detail{
  148. display: grid;
  149. grid-template-rows:1fr 25px;
  150. padding: 10px;
  151. /* 2端对齐 */
  152. place-content: space-between;
  153. }
  154. /* 媒体查询 当宽度小于940px时显示4个 */
  155. @media (max-width:940px) {
  156. .wrap header .entry .content{
  157. grid-template-columns: 80px repeat(4,1fr);
  158. }
  159. .wrap header .entry .content .item .last{
  160. display: none;
  161. }
  162. main .list{
  163. grid-template-columns: repeat(2,1fr);
  164. }
  165. main .navs{
  166. grid-template-columns: 1fr;
  167. }
  168. main .navs > .cate{
  169. display: none;
  170. }
  171. }

实际效果

声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议