Blogger Information
Blog 8
fans 0
comment 0
visits 5412
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
grid 12列栅格布局的组件并仿写页面
L.E
Original
603 people have browsed it

1.栅格布局

  • html 代码
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>12列栅格布局</title>
  7. <link rel="stylesheet" href="grid.css" />
  8. </head>
  9. <body>
  10. <div class="container">
  11. <!-- 先写一行,在行中再定义列 -->
  12. <!-- 1等份 -->
  13. <div class="row">
  14. <span class="item col-12">12列</span>
  15. </div>
  16. <!-- 2等份 -->
  17. <div class="row">
  18. <span class="item col-6">6列</span>
  19. <span class="item col-6">6列</span>
  20. </div>
  21. <!-- 3等份 -->
  22. <div class="row">
  23. <span class="item col-4">4列</span>
  24. <span class="item col-4">4列</span>
  25. <span class="item col-4">4列</span>
  26. </div>
  27. <div class="row">
  28. <span class="item col-3">3列</span>
  29. <span class="item col-9">9列</span>
  30. </div>
  31. </div>
  32. </body>
  33. </html>
  • css 代码
  1. * {
  2. margin: 0;
  3. padding: 0;
  4. box-sizing: border-box;
  5. }
  6. body {
  7. width: 100vw;
  8. height: 100vh;
  9. display: grid;
  10. place-content: center;
  11. }
  12. .container {
  13. min-width: 80vw;
  14. display: grid;
  15. gap: 0.5em;
  16. }
  17. .container .row {
  18. display: grid;
  19. grid-template-columns: repeat(12, 1fr);
  20. min-height: 3em;
  21. gap: 0.5em;
  22. }
  23. .container .row .item {
  24. padding: 1em;
  25. border: 1px solid;
  26. background-color: cyan;
  27. }
  28. .col-12 {
  29. grid-area: auto / span 12;
  30. }
  31. .col-11 {
  32. grid-area: auto / span 11;
  33. }
  34. .col-10 {
  35. grid-area: auto / span 10;
  36. }
  37. .col-9 {
  38. grid-area: auto / span 9;
  39. }
  40. .col-8 {
  41. grid-area: auto / span 8;
  42. }
  43. .col-7 {
  44. grid-area: auto / span 7;
  45. }
  46. .col-6 {
  47. grid-area: auto / span 6;
  48. }
  49. .col-5 {
  50. grid-area: auto / span 5;
  51. }
  52. .col-4 {
  53. grid-area: auto / span 4;
  54. }
  55. .col-3 {
  56. grid-area: auto / span 3;
  57. }
  58. .col-2 {
  59. grid-area: auto / span 2;
  60. }
  61. .col-1 {
  62. grid-area: auto / span 1;
  63. }
  • 效果图

2.仿写 php 中文网手机版首页

  • html 代码
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>12列栅格布局仿写页面</title>
  7. <link rel="stylesheet" href="css/grid.css" />
  8. <link rel="stylesheet" href="css/index.css" />
  9. <style></style>
  10. </head>
  11. <body>
  12. <!-- 页眉 -->
  13. <header>
  14. <div class="container">
  15. <div class="row">
  16. <div class="item col-2">
  17. <a href="" class="user"
  18. ><img src="img/login.png" alt="" class="user-img"
  19. /></a>
  20. </div>
  21. <div class="item col-8">
  22. <a href="" class="logo"
  23. ><img src="img/logo.png" alt="" class="img-logo"
  24. /></a>
  25. </div>
  26. <div class="item col-2">
  27. <img src="img/menu.png" alt="" class="menu-img" />
  28. </div>
  29. </div>
  30. </div>
  31. </header>
  32. <!-- 主体 -->
  33. <main>
  34. <div class="silder">
  35. <ul>
  36. <li><img src="img/3.jpg" alt="" /></li>
  37. </ul>
  38. </div>
  39. <div class="container menus">
  40. <ul class="row">
  41. <li class="col-3">
  42. <a href=""><img src="img/html.png" alt="" />HTML/CSS</a>
  43. </li>
  44. <li class="col-3">
  45. <a href=""><img src="img/JavaScript.png" alt="" />JavaScript</a>
  46. </li>
  47. <li class="col-3">
  48. <a href=""><img src="img/code.png" alt="" />服务器</a>
  49. </li>
  50. <li class="col-3">
  51. <a href=""><img src="img/sql.png" alt="" />数据库</a>
  52. </li>
  53. <li class="col-3">
  54. <a href=""><img src="img/app.png" alt="" />移动端</a>
  55. </li>
  56. <li class="col-3">
  57. <a href=""><img src="img/manual.png" alt="" />手册</a>
  58. </li>
  59. <li class="col-3">
  60. <a href=""><img src="img/tool2.png" alt="" />工具</a>
  61. </li>
  62. <li class="col-3">
  63. <a href=""><img src="img/live.png" alt="" />直播</a>
  64. </li>
  65. </ul>
  66. </div>
  67. <!-- 推荐课程 -->
  68. <div class="container tj">
  69. <div class="title">推荐课程</div>
  70. <div class="row kcgg">
  71. <a class="col-6" href=""
  72. ><img src="img/5e0d82773b4fe808.png" alt=""
  73. /></a>
  74. <a class="col-6" href=""
  75. ><img src="img/5f606a9a7fe99960.jpg" alt=""
  76. /></a>
  77. </div>
  78. <ul class="row kclist">
  79. <li class="col-12">
  80. <a href=""><img src="img/6049da2b3898c385.jpg" alt="" /></a>
  81. <div class="tj-1-intro">
  82. <p><a href="">php8,我来也</a></p>
  83. <p><span class="level">初级</span><span>10000次播放</span></p>
  84. </div>
  85. </li>
  86. <li class="col-12">
  87. <a href=""><img src="img/6049da2b3898c385.jpg" alt="" /></a>
  88. <div class="tj-1-intro">
  89. <p><a href="">php8,我来也</a></p>
  90. <p><span class="level">初级</span><span>10000次播放</span></p>
  91. </div>
  92. </li>
  93. </ul>
  94. </div>
  95. <!-- 最新更新 -->
  96. <div class="container zx">
  97. <div class="title">最新更新</div>
  98. <ul class="row kclist">
  99. <li class="col-12">
  100. <a href=""><img src="img/6077f6ddce966562.png" alt="" /></a>
  101. <div class="zx-1-intro">
  102. <p><a href="">Web开发进阶—jQuery</a></p>
  103. <p class="zx-info">
  104. jQuery是一个 快速
  105. 简洁的JavaScript框架,它封装JavaScript常用的功能代码
  106. 提供一种简便的JavaScript设计模式。本套课程将带领大家进入jQuery的学习……
  107. </p>
  108. <p><span class="level">初级</span><span>888次播放</span></p>
  109. </div>
  110. </li>
  111. <li class="col-12">
  112. <a href=""><img src="img/6077f6ddce966562.png" alt="" /></a>
  113. <div class="zx-1-intro">
  114. <p><a href="">Web开发进阶—jQuery</a></p>
  115. <p class="zx-info">
  116. jQuery是一个 快速
  117. 简洁的JavaScript框架,它封装JavaScript常用的功能代码
  118. 提供一种简便的JavaScript设计模式。本套课程将带领大家进入jQuery的学习……
  119. </p>
  120. <p><span class="level">初级</span><span>888次播放</span></p>
  121. </div>
  122. </li>
  123. <li class="col-12">
  124. <a href=""><img src="img/6077f6ddce966562.png" alt="" /></a>
  125. <div class="zx-1-intro">
  126. <p><a href="">Web开发进阶—jQuery</a></p>
  127. <p class="zx-info">
  128. jQuery是一个 快速
  129. 简洁的JavaScript框架,它封装JavaScript常用的功能代码
  130. 提供一种简便的JavaScript设计模式。本套课程将带领大家进入jQuery的学习……
  131. </p>
  132. <p><span class="level">初级</span><span>888次播放</span></p>
  133. </div>
  134. </li>
  135. <li class="col-12">
  136. <a href=""><img src="img/6077f6ddce966562.png" alt="" /></a>
  137. <div class="zx-1-intro">
  138. <p><a href="">Web开发进阶—jQuery</a></p>
  139. <p class="zx-info">
  140. jQuery是一个 快速
  141. 简洁的JavaScript框架,它封装JavaScript常用的功能代码
  142. 提供一种简便的JavaScript设计模式。本套课程将带领大家进入jQuery的学习……
  143. </p>
  144. <p><span class="level">初级</span><span>888次播放</span></p>
  145. </div>
  146. </li>
  147. <li class="col-12">
  148. <a href=""><img src="img/6077f6ddce966562.png" alt="" /></a>
  149. <div class="zx-1-intro">
  150. <p><a href="">Web开发进阶—jQuery</a></p>
  151. <p class="zx-info">
  152. jQuery是一个 快速
  153. 简洁的JavaScript框架,它封装JavaScript常用的功能代码
  154. 提供一种简便的JavaScript设计模式。本套课程将带领大家进入jQuery的学习……
  155. </p>
  156. <p><span class="level">初级</span><span>888次播放</span></p>
  157. </div>
  158. </li>
  159. <li class="col-12">
  160. <a href=""><img src="img/6077f6ddce966562.png" alt="" /></a>
  161. <div class="zx-1-intro">
  162. <p><a href="">Web开发进阶—jQuery</a></p>
  163. <p class="zx-info">
  164. jQuery是一个 快速
  165. 简洁的JavaScript框架,它封装JavaScript常用的功能代码
  166. 提供一种简便的JavaScript设计模式。本套课程将带领大家进入jQuery的学习……
  167. </p>
  168. <p><span class="level">初级</span><span>888次播放</span></p>
  169. </div>
  170. </li>
  171. </ul>
  172. </div>
  173. </main>
  174. <!-- 页脚 -->
  175. <footer>
  176. <nav class="footer-navs">
  177. <a href=""><img src="img/home.png" alt="" />首页</a>
  178. <a href=""><img src="img/video.png" alt="" />视频</a>
  179. <a href=""><img src="img/live2.png" alt="" />直播</a>
  180. <a href=""><img src="img/community.png" alt="" />社区</a>
  181. <a href=""><img src="img/my.png" alt="" />我的</a>
  182. </nav>
  183. </footer>
  184. </body>
  185. </html>
  • css 代码

grid.css

  1. * {
  2. margin: 0;
  3. padding: 0;
  4. box-sizing: border-box;
  5. }
  6. .container {
  7. min-width: 80vw;
  8. display: grid;
  9. gap: 0.5em;
  10. }
  11. .container .row {
  12. display: grid;
  13. /* 任何一行都是由12列组成 */
  14. grid-template-columns: repeat(12, 1fr);
  15. min-height: 3em;
  16. gap: 0.5em;
  17. }
  18. .container .row .item {
  19. padding: 1em;
  20. border: 1px solid;
  21. background-color: cyan;
  22. }
  23. .col-12 {
  24. grid-area: auto / span 12;
  25. }
  26. .col-11 {
  27. grid-area: auto / span 11;
  28. }
  29. .col-10 {
  30. grid-area: auto / span 10;
  31. }
  32. .col-9 {
  33. grid-area: auto / span 9;
  34. }
  35. .col-8 {
  36. grid-area: auto / span 8;
  37. }
  38. .col-7 {
  39. grid-area: auto / span 7;
  40. }
  41. .col-6 {
  42. grid-area: auto / span 6;
  43. }
  44. .col-5 {
  45. grid-area: auto / span 5;
  46. }
  47. .col-4 {
  48. grid-area: auto / span 4;
  49. }
  50. .col-3 {
  51. grid-area: auto / span 3;
  52. }
  53. .col-2 {
  54. grid-area: auto / span 2;
  55. }
  56. .col-1 {
  57. grid-area: auto / span 1;
  58. }

index.css

  1. body {
  2. background-color: #edeff0;
  3. }
  4. a {
  5. text-decoration: none;
  6. color: #888;
  7. }
  8. li {
  9. list-style: none;
  10. }
  11. /* 页眉 */
  12. header {
  13. background-color: #2d353c;
  14. position: fixed;
  15. width: 100%;
  16. top: 0;
  17. height: 3em;
  18. }
  19. header .item {
  20. height: 3em;
  21. text-align: center;
  22. }
  23. header .user .user-img {
  24. width: 2em;
  25. margin: 0.5em 0 0 0;
  26. border: 1px solid #8f9498;
  27. border-radius: 50%;
  28. }
  29. header .logo .img-logo {
  30. height: 100%;
  31. }
  32. header .menu-img {
  33. margin: 1em 0 0 0;
  34. }
  35. /* 主体 */
  36. main {
  37. margin-top: 3em;
  38. }
  39. main .silder {
  40. height: 10em;
  41. }
  42. main .silder ul li img {
  43. width: 100%;
  44. height: 10em;
  45. }
  46. main .menus {
  47. text-align: center;
  48. font-size: 14px;
  49. font-weight: bolder;
  50. background-color: #fff;
  51. padding-bottom: 1em;
  52. }
  53. main .menus ul li {
  54. margin-top: 1em;
  55. }
  56. main .menus ul li a img {
  57. width: 3em;
  58. height: 3em;
  59. display: block;
  60. margin: 0 auto;
  61. }
  62. /* 推荐课程 */
  63. main .tj {
  64. padding: 2em 0.5em 0;
  65. }
  66. main .tj .title {
  67. font-size: 18px;
  68. font-weight: bolder;
  69. color: #888;
  70. }
  71. main .tj .kcgg a img {
  72. width: 100%;
  73. height: auto;
  74. }
  75. main .tj .kclist li {
  76. background-color: #fff;
  77. padding: 0.5em;
  78. display: grid;
  79. grid-template-columns: 40% 1fr;
  80. margin-bottom: 1em;
  81. }
  82. main .tj .kclist a img {
  83. width: 100%;
  84. height: auto;
  85. }
  86. main .tj .kclist .tj-1-intro {
  87. margin: 0 0.5em;
  88. }
  89. main .tj .kclist .tj-1-intro p {
  90. margin-bottom: 0.5em;
  91. }
  92. main .tj .kclist .tj-1-intro p span {
  93. font-size: 12px;
  94. color: #888;
  95. }
  96. main .tj .kclist .tj-1-intro p span.level {
  97. background-color: #595757;
  98. color: #fff;
  99. padding: 3px;
  100. border-radius: 8px;
  101. }
  102. /* 最新更新 */
  103. main .zx {
  104. padding: 2em 0.5em 0;
  105. margin-bottom: 3.5em;
  106. }
  107. main .zx .title {
  108. font-size: 18px;
  109. font-weight: bolder;
  110. color: #888;
  111. }
  112. main .zx .kclist li {
  113. background-color: #fff;
  114. padding: 0.5em;
  115. display: grid;
  116. grid-template-columns: 40% 60%;
  117. margin-bottom: 1em;
  118. }
  119. main .zx .kclist a img {
  120. width: 100%;
  121. height: auto;
  122. }
  123. main .zx .kclist .zx-1-intro {
  124. margin: 0 0.5em;
  125. }
  126. main .zx .kclist .zx-1-intro p {
  127. margin-bottom: 0.5em;
  128. display: block;
  129. }
  130. main .zx .kclist .zx-1-intro p.zx-info {
  131. font-size: 12px;
  132. color: #888;
  133. overflow: hidden;
  134. white-space: nowrap;
  135. text-overflow: ellipsis;
  136. }
  137. main .zx .kclist .zx-1-intro p span {
  138. font-size: 12px;
  139. color: #888;
  140. }
  141. main .zx .kclist .zx-1-intro p span.level {
  142. background-color: #595757;
  143. color: #fff;
  144. padding: 3px;
  145. border-radius: 8px;
  146. }
  147. main .zx .kclist .zx-info + p {
  148. display: flex;
  149. justify-content: space-between;
  150. }
  151. /* 页脚 */
  152. footer {
  153. width: 100%;
  154. height: 3.5em;
  155. bottom: 0;
  156. position: fixed;
  157. display: flex;
  158. justify-content: space-around;
  159. align-items: center;
  160. background-color: #edeff0;
  161. border-top: 1px solid #ccc;
  162. }
  163. footer nav {
  164. display: flex;
  165. flex-flow: row wrap;
  166. justify-content: space-between;
  167. width: 100%;
  168. }
  169. footer nav a {
  170. display: flex;
  171. flex-flow: column nowrap;
  172. align-items: center;
  173. width: 20%;
  174. font-size: 14px;
  175. }
  • 效果图
Correcting teacher:天蓬老师天蓬老师

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