博客列表 >【CSS】 PC端布局-实战淘宝

【CSS】 PC端布局-实战淘宝

可乐随笔
可乐随笔原创
2022年11月27日 20:21:06334浏览

PC端布局-实战淘宝

  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. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  7. <link rel="stylesheet" href="css/pcmain.css" />
  8. <title>PC端布局-实战淘宝</title>
  9. </head>
  10. <body>
  11. <div class="wrap">
  12. <header>
  13. <!-- 头部 -->
  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. <!-- 主体 -->
  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. <!-- 左侧分类 -->
  40. <div class="navs">
  41. <div class="cate">
  42. </div>
  43. <!-- 右侧轮播图和用户信息 -->
  44. <div class="user">
  45. <!-- 顶部导航 -->
  46. <div class="user-top">
  47. .
  48. </div>
  49. <!-- 左侧轮播图 -->
  50. <div class="slider"></div>
  51. <!-- 右侧用户信息 -->
  52. <div class="user-info"></div>
  53. </div>
  54. </div>
  55. <div class="title">
  56. <h2>猜你喜欢</h2>
  57. <div class="tag">个性推荐</div>
  58. </div>
  59. <div class="list">
  60. <div class="item">
  61. <a href=""><img src="images/items/item-20.webp" alt=""></a>
  62. <div class="detail">
  63. <div class="desc">商品描述</div>
  64. <div class="price">105</div>
  65. </div>
  66. </div>
  67. <div class="item">
  68. <a href=""><img src="images/items/item-20.webp" alt=""></a>
  69. <div class="detail">
  70. <div class="desc">商品描述</div>
  71. <div class="price">105</div>
  72. </div>
  73. </div>
  74. <div class="item">
  75. <a href=""><img src="images/items/item-20.webp" alt=""></a>
  76. <div class="detail">
  77. <div class="desc">商品描述</div>
  78. <div class="price">105</div>
  79. </div>
  80. </div>
  81. <div class="item">
  82. <a href=""><img src="images/items/item-20.webp" alt=""></a>
  83. <div class="detail">
  84. <div class="desc">商品描述</div>
  85. <div class="price">105</div>
  86. </div>
  87. </div>
  88. <div class="item">
  89. <a href=""><img src="images/items/item-20.webp" alt=""></a>
  90. <div class="detail">
  91. <div class="desc">商品描述</div>
  92. <div class="price">105</div>
  93. </div>
  94. </div>
  95. <div class="item">
  96. <a href=""><img src="images/items/item-20.webp" alt=""></a>
  97. <div class="detail">
  98. <div class="desc">商品描述</div>
  99. <div class="price">105</div>
  100. </div>
  101. </div>
  102. <div class="item">
  103. <a href=""><img src="images/items/item-20.webp" alt=""></a>
  104. <div class="detail">
  105. <div class="desc">商品描述</div>
  106. <div class="price">105</div>
  107. </div>
  108. </div>
  109. <div class="item">
  110. <a href=""><img src="images/items/item-20.webp" alt=""></a>
  111. <div class="detail">
  112. <div class="desc">商品描述</div>
  113. <div class="price">105</div>
  114. </div>
  115. </div>
  116. <div class="item">
  117. <a href=""><img src="images/items/item-20.webp" alt=""></a>
  118. <div class="detail">
  119. <div class="desc">商品描述</div>
  120. <div class="price">105</div>
  121. </div>
  122. </div>
  123. </div>
  124. </main>
  125. </div>
  126. </body>
  127. </html>

CSS

  1. * {
  2. margin: 0;
  3. padding: 0;
  4. box-sizing: border-box;
  5. }
  6. body {
  7. min-height: 2000px;
  8. }
  9. .wrap header .top {
  10. width: 100vw;
  11. height: 36px;
  12. background-color: yellow;
  13. }
  14. .wrap header .top .content {
  15. width: 1190px;
  16. height: inherit;
  17. margin: auto;
  18. background-color: wheat;
  19. }
  20. /* 头部快速入口 */
  21. .wrap header .entry {
  22. height: 100px;
  23. padding: 15px;
  24. /* background-color: #ccc; */
  25. }
  26. .wrap header .entry .content {
  27. max-width: 1190px;
  28. min-width: 940px;
  29. height: inherit;
  30. background-color: aquamarine;
  31. margin: auto;
  32. display: grid;
  33. grid-template-columns: 80px repeat(5,1fr);
  34. grid-auto-rows: 80px;
  35. gap: 10px;
  36. padding: 10px;
  37. }
  38. .wrap header .entry .content .item {
  39. background-color: #fff;
  40. border-radius: 15px;
  41. }
  42. /* 主体 */
  43. .wrap main {
  44. max-width: 1190px;
  45. min-width: 740px;
  46. background-color: lightgreen;
  47. min-height: 1000px;
  48. margin: 20px auto;
  49. padding: 20px;
  50. }
  51. /* 搜索框 */
  52. .wrap main .search {
  53. height: 88px;
  54. display: grid;
  55. grid-template-columns: 190px 1fr 90px;
  56. /* 1fr:自适应 */
  57. gap: 10px;
  58. /* 粘性定位 */
  59. position: sticky;
  60. top: 0;
  61. }
  62. .wrap main .search .item {
  63. background-color: lightpink;
  64. }
  65. /* 主体导航区 */
  66. .wrap main .navs {
  67. height: 423px;
  68. margin: 20px 0;
  69. display: grid;
  70. grid-template-columns: 270px 1fr;
  71. gap: 10px;
  72. }
  73. .wrap main .navs .cate {
  74. background-color: lightskyblue;
  75. }
  76. .wrap main .user {
  77. display: grid;
  78. grid-template-columns: 564px 1fr;
  79. grid-template-rows: 42px 1fr;
  80. gap: 10px;
  81. }
  82. .wrap main .user > * {
  83. background-color: aquamarine;
  84. }
  85. .wrap main .user .user-top {
  86. grid-column: span 2;
  87. }
  88. /* 主体标题区 */
  89. .wrap main .title {
  90. background-color: lightcyan;
  91. display: flex;
  92. place-items: center;
  93. }
  94. .wrap main .title .tag {
  95. background: linear-gradient(to left,orangered,orange);
  96. border-radius: 3px;
  97. color: #fff;
  98. margin-left: 6px;
  99. padding: 0 5px;
  100. cursor: default;
  101. }
  102. /* 主体:商品列表 */
  103. .wrap 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. .wrap 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. .wrap main .list .item > * {
  119. background-color: antiquewhite;
  120. border-radius: 6px;;
  121. }
  122. .wrap main .list .item img {
  123. width: 100%;
  124. border-radius: 6px;
  125. }
  126. .wrap main .list .item .detail {
  127. display: grid;
  128. grid-template-rows: 1fr 25px;
  129. padding: 10px;
  130. /* 要加place-content:space-between 适应响应式*/
  131. place-content: space-between;
  132. }
  133. /* 媒体查询:响应式布局 */
  134. @media (max-width: 940px){
  135. .wrap header .entry .content {
  136. grid-template-columns: 80px repeat(4,1fr);
  137. }
  138. .wrap main .list {
  139. grid-template-columns: repeat(2,1fr);
  140. }
  141. /* 屏幕宽度小于740PX时,隐藏菜单 */
  142. .wrap main .navs .cate {
  143. display: none;
  144. }
  145. /* 屏幕宽度小于740PX时,修改布局为一列 */
  146. .wrap main .navs {
  147. grid-template-columns: 1fr;
  148. }
  149. }
声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议