Blogger Information
Blog 23
fans 0
comment 3
visits 23609
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Grid布局中项目在单元格和容器中对齐方式、防PHP中文网首页、grid媒体查询理解
a.
Original
1049 people have browsed it

一.Grid布局中项目在单元格和容器中对齐方式

1. 项目在单元格中的对齐方式

  • 项目在单元格中对齐方式分为如下两种:
编号 属性 说明
1. place-items 所有项目在网格单元中的对齐方式
2. place-self 某个项目在网格单元中的对齐方式

1.1 place-items属性:所有项目在网格单元中的对齐方式

  1. /*左上角*/
  2. place-items:start;
  3. /*上中*/
  4. place-items:start center;
  5. /*右上角*/
  6. place-items:start end;
  7. /*da下角*/
  8. place-items:end start;
  9. /*中下*/
  10. place-items:end center;
  11. /*右下角*/
  12. place-items:end;
  13. /*水平垂直居中*/
  14. place-items:center;

1.2 place-self属性:某个项目在网格单元中的对齐方式

  • !这个属性必须用在项目上
  1. <html>
  2. <head>
  3. <meta charset="utf-8" />
  4. <style>
  5. .container {
  6. border: solid 1px blue;
  7. display: grid;
  8. grid-template-columns: repeat(3, 8em);
  9. grid-template-rows: repeat(2, 8em);
  10. place-items: end;
  11. gap: 0.5em;
  12. /* place-content:space-around space-evenly; */
  13. }
  14. .container > .item {
  15. background-color: red;
  16. width: 5em;
  17. height: 5em;
  18. }
  19. .container > .item:nth-of-type(2) {
  20. place-self: start;
  21. }
  22. </style>
  23. </head>
  24. <body>
  25. <div class="container">
  26. <div class="item">1</div>
  27. <div class="item">2</div>
  28. <div class="item">3</div>
  29. <div class="item">4</div>
  30. <div class="item">5</div>
  31. <div class="item">6</div>
  32. </div>
  33. </body>
  34. </html>

2. 将所有项目做为一个整体在容器中对齐

  • 有剩余空间时才有效果

属性语法:place-content:垂直方向 水平方向

3. 将所有项目打散成独立个体在容器中对齐

属性place-content常用值:

  1. place-content:space-between;
  2. place-content:space-around;
  3. place-content:space-evenly;

  1. <html>
  2. <head>
  3. <meta charset="utf-8" />
  4. <style>
  5. .container {
  6. border: solid 1px blue;
  7. display: grid;
  8. grid-template-columns: repeat(3, 8em);
  9. grid-template-rows: repeat(2, 8em);
  10. /* place-items: end; */
  11. gap: 0.5em;
  12. place-content: space-between;
  13. place-content: space-around;
  14. place-content: space-evenly;
  15. place-content: space-around space-evenly;
  16. }
  17. .container > .item {
  18. background-color: red;
  19. width: 5em;
  20. height: 5em;
  21. }
  22. /* .container > .item:nth-of-type(2) {
  23. place-self: start;
  24. } */
  25. </style>
  26. </head>
  27. <body>
  28. <div class="container">
  29. <div class="item">1</div>
  30. <div class="item">2</div>
  31. <div class="item">3</div>
  32. <div class="item">4</div>
  33. <div class="item">5</div>
  34. <div class="item">6</div>
  35. </div>
  36. </body>
  37. </html>

二.仿PHP中文网首页

效果图


代码

HMLT

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <link rel="stylesheet" href="style.css" />
  7. <title>php中文网欢迎你</title>
  8. </head>
  9. <body>
  10. <header>
  11. <div class="logo"></div>
  12. <ul class="top-nav">
  13. <li><a href="#">首页</a></li>
  14. <li><a href="">视频教程</a></li>
  15. <li><a href="">入门教程</a></li>
  16. <li><a href="">社区问答</a></li>
  17. <li><a href="">技术文章</a></li>
  18. <li><a href="">资源下载</a></li>
  19. <li><a href="">工具下载</a></li>
  20. <li><a href="">PHP培训</a><span class="nav-new"></span></li>
  21. </ul>
  22. <ul class="user">
  23. <li><a href="">登录</a></li>
  24. <li><a href="">注册</a></li>
  25. </ul>
  26. </header>
  27. <main class="main">
  28. <div class="main-top">
  29. <div class="main-menus">
  30. <ul>
  31. <li><a href="">php开发</a></li>
  32. <li><a href="">前端开发</a></li>
  33. <li><a href="">服务端开发</a></li>
  34. <li><a href="">移动开发</a></li>
  35. <li><a href="">数据库</a></li>
  36. <li><a href="">服务器运维</a></li>
  37. <li><a href="">在线工具</a></li>
  38. <li><a href="">常用类库</a></li>
  39. </ul>
  40. </div>
  41. <div class="main-navs">
  42. <ul>
  43. <li><a href="">php头条</a></li>
  44. <li><a href="">独孤9贱</a></li>
  45. <li><a href="">学习路线</a></li>
  46. <li><a href="">在线工具</a></li>
  47. <li><a href="">趣味课堂</a></li>
  48. <li><a href="">社区问答</a></li>
  49. <li><a href="">课程直播</a></li>
  50. <li>
  51. <input type="text" placeholder="请输入关键词搜索" /><a href=""
  52. ><span class="iconfont icon-sousuo"></span
  53. ></a>
  54. </li>
  55. </ul>
  56. </div>
  57. <div class="main-img">
  58. <a href=""
  59. ><img
  60. src="https://img.php.cn/upload/article/000/000/001/5fabba9a8557c153.jpg"
  61. /></a>
  62. </div>
  63. <div class="main-footer">
  64. <ul>
  65. <li>
  66. <a href=""
  67. ><img
  68. src="https://www.php.cn/static/images/index_yunv.jpg"
  69. alt=""
  70. /></a>
  71. </li>
  72. <li>
  73. <a href=""
  74. ><img
  75. src="https://www.php.cn/static/images/index_php_item2_.png?1"
  76. alt=""
  77. /></a>
  78. </li>
  79. <li>
  80. <a href=""
  81. ><img
  82. src="https://www.php.cn/static/images/index_php_item3.jpg?1"
  83. alt=""
  84. /></a>
  85. </li>
  86. <li>
  87. <a href=""
  88. ><img
  89. src="https://www.php.cn/static/images/index_php_new4.jpg?1"
  90. alt=""
  91. /></a>
  92. </li>
  93. </ul>
  94. </div>
  95. </div>
  96. <div class="main-tt">
  97. <div class="article">
  98. <h5>头条</h5>
  99. <ul>
  100. <li><a href="">值得研究的20个Vue开源项目</a></li>
  101. <li><a href="">值得研究的20个Vue开源项目</a></li>
  102. <li><a href="">值得研究的20个Vue开源项目</a></li>
  103. <li><a href="">值得研究的20个Vue开源项目</a></li>
  104. <li><a href="">值得研究的20个Vue开源项目</a></li>
  105. <li><a href="">值得研究的20个Vue开源项目</a></li>
  106. <li><a href="">值得研究的20个Vue开源项目</a></li>
  107. <li><a href="">值得研究的20个Vue开源项目</a></li>
  108. <li><a href="">值得研究的20个Vue开源项目</a></li>
  109. <li><a href="">值得研究的20个Vue开源项目</a></li>
  110. <li><a href="">值得研究的20个Vue开源项目</a></li>
  111. <li><a href="">值得研究的20个Vue开源项目</a></li>
  112. </ul>
  113. </div>
  114. <div class="course">
  115. <h5>最新课程</h5>
  116. <ul>
  117. <li>
  118. <a href=""
  119. ><img
  120. src="https://img.php.cn/upload/course/000/000/015/5fe53f35072f4326.png"
  121. alt=""
  122. /><span><lable>高级</lable>通用后台系统实战开发</span></a
  123. >
  124. </li>
  125. <li>
  126. <a href=""
  127. ><img
  128. src="https://img.php.cn/upload/course/000/000/015/5fe3e7ef18250408.png"
  129. alt=""
  130. /><span><lable>高级</lable>通用后台系统实战开发</span></a
  131. >
  132. </li>
  133. <li>
  134. <a href=""
  135. ><img
  136. src="https://img.php.cn/upload/course/000/000/015/5fe29e6d8e573924.png"
  137. alt=""
  138. /><span><lable>高级</lable>通用后台系统实战开发</span></a
  139. >
  140. </li>
  141. <li>
  142. <a href=""
  143. ><img
  144. src="https://img.php.cn/upload/course/000/000/015/5fe14c671e418955.png"
  145. alt=""
  146. /><span><lable>高级</lable>通用后台系统实战开发</span></a
  147. >
  148. </li>
  149. <li>
  150. <a href=""
  151. ><img
  152. src="https://img.php.cn/upload/course/000/000/015/5fe03ee146db6354.png"
  153. alt=""
  154. /><span><lable>高级</lable>通用后台系统实战开发</span></a
  155. >
  156. </li>
  157. <li>
  158. <a href=""
  159. ><img
  160. src="https://img.php.cn/upload/course/000/000/001/5fd08fcece8ef207.jpg"
  161. alt=""
  162. /><span><lable>高级</lable>通用后台系统实战开发</span></a
  163. >
  164. </li>
  165. </ul>
  166. </div>
  167. <div class="manual">
  168. <h5>常用手册</h5>
  169. <ul>
  170. <li>
  171. <img
  172. src="https://www.php.cn/upload/system/000/000/001/57d55fe881432245.jpg"
  173. />
  174. <div><a href="">php手册Linux手册</a> <a href="">php手册Linux手册</a>
  175. </li>
  176. <li>
  177. <img
  178. src="https://www.php.cn/upload/system/000/000/001/57d55fe881432245.jpg"
  179. />
  180. <div><a href="">php手册Linux手册</a> <a href="">php手册Linux手册</a>
  181. </div></li>
  182. <li>
  183. <img
  184. src="https://www.php.cn/upload/system/000/000/001/57d55fe881432245.jpg"
  185. /><div>
  186. <a href="">php手册Linux手册</a> <a href="">php手册Linux手册</a>
  187. </div></li>
  188. <li>
  189. <img
  190. src="https://www.php.cn/upload/system/000/000/001/57d55fe881432245.jpg"
  191. /><div><a href="">php手册Linux手册</a> <a href="">php手册Linux手册</a>
  192. </div>
  193. </li>
  194. <li>
  195. <img
  196. src="https://www.php.cn/upload/system/000/000/001/57d55fe881432245.jpg"
  197. /><div>
  198. <a href="">php手册Linux手册</a><a href="">php手册Linux手册</a>
  199. </div></li>
  200. <li>
  201. <img
  202. src="https://www.php.cn/upload/system/000/000/001/57d55fe881432245.jpg"
  203. /><div>
  204. <a href="">php手册Linux手册</a><a href="">php手册Linux手册</a>
  205. </div></li>
  206. </ul>
  207. </div>
  208. </div>
  209. <div class="r-course">
  210. <h3><span> &lt;/&gt; </span> php入门精品课程 <span> &lt;/&gt; </span> </h3>
  211. <div class="r-body">
  212. <div><img src="https://www.php.cn/static/images/index_learn_first.jpg" alt=""></div>
  213. <div><a href=""><img src="https://img.php.cn/upload/course/000/000/001/5b63c72c61569244.png" alt=""><span><label>初级</label>编程学习方法分享直播公益课<span>1w+播放</span></span></a></div>
  214. <div><a href=""><img src="https://img.php.cn/upload/course/000/126/153/5aa23f0ded921649.jpg" alt=""><span><label>初级</label>编程学习方法分享直播公益课<span>1w+播放</span></span></a></div>
  215. <div><a href=""><img src="https://img.php.cn/upload/course/000/126/153/5ab346fc62ce4221.jpg" alt=""><span><label>初级</label>编程学习方法分享直播公益课<span>1w+播放</span></span></a></div>
  216. <div><a href=""><img src="https://img.php.cn/upload/course/000/126/153/5acc118f11d6b969.jpg" alt=""><span><label>初级</label>编程学习方法分享直播公益课<span>1w+播放</span></span></a></div>
  217. <div><a href=""><img src="https://img.php.cn/upload/course/000/000/001/5d1c6e0d2b744633.jpg" alt=""><span><label>初级</label>编程学习方法分享直播公益课<span>1w+播放</span></span></a></div>
  218. <div><a href=""><img src="https://img.php.cn/upload/course/000/000/001/5d24019911a24370.jpg" alt=""><span><label>初级</label>编程学习方法分享直播公益课<span>1w+播放</span></span></a></div>
  219. <div><a href=""><img src="https://img.php.cn/upload/course/000/000/003/5a699f1b2da2b398.jpg" alt=""><span><label>初级</label>编程学习方法分享直播公益课<span>1w+播放</span></span></a></div>
  220. <div><a href=""><img src="https://img.php.cn/upload/course/000/000/001/5cecd27a4348b582.jpg" alt=""><span><label>初级</label>编程学习方法分享直播公益课<span>1w+播放</span></span></a></div>
  221. <div><a href=""><img src="https://img.php.cn/upload/course/000/000/001/5d1c6dfc9eb09885.jpg" alt=""><span><label>初级</label>编程学习方法分享直播公益课<span>1w+播放</span></span></a></div>
  222. <div><a href=""><img src="https://img.php.cn/upload/course/000/000/003/5a13c87351613730.jpg" alt=""><span><label>初级</label>编程学习方法分享直播公益课<span>1w+播放</span></span></a></div>
  223. <div><a href=""><img src="https://img.php.cn/upload/course/000/171/829/5b19ef2990649817.jpg" alt=""><span><label>初级</label>编程学习方法分享直播公益课<span>1w+播放</span></span></a></div>
  224. <div><a href=""><img src="https://img.php.cn/upload/course/000/000/001/5d240300be85b731.jpg" alt=""><span><label>初级</label>编程学习方法分享直播公益课<span>1w+播放</span></span></a></div>
  225. <div><a href=""><img src="https://img.php.cn/upload/course/000/001/120/5a9fb97057b15707.jpeg" alt=""><span><label>初级</label>编程学习方法分享直播公益课<span>1w+播放</span></span></a></div>
  226. </div>
  227. </div>
  228. </main>
  229. <footer>
  230. <div></div>
  231. <div class="link">
  232. <ul>
  233. <li><a href="">网站首页</a></li>
  234. <li><a href="">php视频</a></li>
  235. <li><a href="">PHP实战</a></li>
  236. <li><a href="">PHP代码</a></li>
  237. </ul>
  238. </div>
  239. <div></div>
  240. <p>php中文网:公益在线php培训,帮助PHP学习者快速成长!</p>
  241. <p>Copyright 2014-2020 https://www.php.cn/ All Rights Reserved | 苏州跃动光标网络科技有限公司 | 苏ICP备2020058653号-1 </p>
  242. </footer>
  243. </body>
  244. </html>

CSS

reset.css

  1. * {
  2. margin: 0;
  3. padding: 0;
  4. box-sizing: border-box;
  5. list-style: none;
  6. }
  7. a {
  8. text-decoration: none;
  9. color: rgb(107, 104, 104);
  10. }
  11. body {
  12. background-color: #f7f7f7;
  13. }

index.css

  1. @import "reset.css";
  2. @import url(https://at.alicdn.com/t/font_2289194_lcufc1dn8s.css);
  3. header {
  4. background-color: #000;
  5. display: grid;
  6. grid-template-columns: 140px 1fr 120px;
  7. grid-template-rows: 60px;
  8. gap: 2px;
  9. box-shadow: 0 4px 8px 0 rgba(7, 17, 27, 0.1);
  10. }
  11. header .logo {
  12. background: url(https://www.php.cn/static/images/logo.png) no-repeat left
  13. center;
  14. background-size: 90%;
  15. }
  16. header .top-nav {
  17. display: grid;
  18. grid-template-rows: 1fr;
  19. grid-template-columns: 72px repeat(7, 104px);
  20. place-items: center;
  21. }
  22. header .top-nav li {
  23. width: 100%;
  24. height: 60px;
  25. text-align: center;
  26. line-height: 60px;
  27. }
  28. header .top-nav li .nav-new {
  29. display: inline-block;
  30. line-height: 18px;
  31. width: 18px;
  32. /* font-weight: normal; */
  33. font-size: 14px;
  34. background-color: red;
  35. color: rgb(255, 255, 255);
  36. position: relative;
  37. /* border: solid violet 1px; */
  38. border-radius: 3px;
  39. top: -15px;
  40. }
  41. header .top-nav li:first-of-type {
  42. background-color: #363c41;
  43. }
  44. header .user {
  45. font-weight: bold;
  46. }
  47. header .user {
  48. display: grid;
  49. grid-template-rows: 1fr;
  50. grid-template-columns: 60px 60px;
  51. place-items: center;
  52. }
  53. header .top-nav a,
  54. header .user a {
  55. color: rgb(223, 221, 221);
  56. font-size: 14px;
  57. }
  58. header .top-nav a:hover,
  59. header .user a:hover {
  60. color: #fff;
  61. }
  62. .main {
  63. width: 1200px;
  64. margin: 30px auto;
  65. }
  66. .main > .main-top {
  67. display: grid;
  68. place-content: center;
  69. grid-template-columns: 215px repeat(4, 1fr);
  70. grid-template-rows: 60px 330px 105px;
  71. border-radius: 10px;
  72. box-shadow: 5px 5px 5px 0 rgba(0, 0, 0, 0.05);
  73. }
  74. .main > .main-top div:first-of-type {
  75. grid-area: span 3;
  76. border-start-start-radius: 10px;
  77. border-end-start-radius: 10px;
  78. }
  79. .main > .main-top div:nth-of-type(2) {
  80. grid-area: auto / span 4;
  81. border-start-end-radius: 10px;
  82. background-color: #fff;
  83. }
  84. .main > .main-top div:nth-of-type(3) {
  85. grid-area: auto / span 4;
  86. }
  87. .main > .main-top div:nth-of-type(4) {
  88. grid-area: auto / span 4;
  89. border-end-end-radius: 10px;
  90. }
  91. .main .main-top .main-menus {
  92. background-color: #2b333b;
  93. }
  94. .main .main-top .main-menus ul {
  95. display: grid;
  96. grid-template-rows: repeat(8, 1fr);
  97. grid-template-columns: 1fr;
  98. /* width: 235px;*/
  99. height: 100%;
  100. place-items: center start;
  101. /* gap: 5px; */
  102. }
  103. .main .main-top .main-menus ul li {
  104. margin-left: 30px;
  105. }
  106. .main .main-top .main-menus ul li a {
  107. color: rgba(255, 255, 255, 0.6);
  108. }
  109. .main .main-top .main-menus ul li:first-of-type {
  110. margin-top: 10px;
  111. }
  112. .main .main-top .main-menus ul li:last-of-type {
  113. margin-bottom: 10px;
  114. }
  115. .main .main-top .main-navs ul li input {
  116. border-radius: 3px;
  117. border: none;
  118. background-color: #f1f0f0;
  119. height: 40px;
  120. width: 250px;
  121. padding: 0 12px;
  122. border-bottom: solid 1px #ccc;
  123. }
  124. .main .main-top .main-navs ul li a span {
  125. position: relative;
  126. right: 30px;
  127. top: 2px;
  128. }
  129. .main .main-top .main-navs ul {
  130. display: grid;
  131. grid-template-columns: repeat(7, 1fr) 280px;
  132. grid-template-rows: 1fr;
  133. height: 100%;
  134. place-items: center;
  135. }
  136. .main .main-top .main-img a img {
  137. width: 985px;
  138. }
  139. .main .main-top .main-footer ul {
  140. height: 100%;
  141. display: grid;
  142. grid-template-columns: repeat(4, 1fr);
  143. grid-template-rows: 1fr;
  144. }
  145. .main .main-top .main-footer ul li a img {
  146. border-radius: 8px;
  147. width: 235px;
  148. margin: 8px 4px;
  149. }
  150. /*****/
  151. .main .main-tt {
  152. display: grid;
  153. grid-template-columns: 300px 620px 260px;
  154. grid-template-rows: 450px;
  155. gap: 10px;
  156. /* background-color: #fff; */
  157. margin: 20px auto;
  158. border-radius: 10px;
  159. }
  160. .main .main-tt .article,
  161. .main .main-tt .course,
  162. .main .main-tt .manual,
  163. .main .main-tt .course ul li {
  164. background-color: #fff;
  165. border-radius: 10px;
  166. box-shadow: 0 4px 8px 0 #ccc;
  167. }
  168. .main .main-tt .article {
  169. display: grid;
  170. grid-template-rows: 40px 1fr;
  171. }
  172. .main .main-tt * h5 {
  173. margin: 7px 20px;
  174. padding: 0 20px;
  175. border-bottom: dotted 1px #ccc;
  176. }
  177. .main .main-tt .article ul {
  178. display: grid;
  179. grid-template-rows: repeat(12, 1fr);
  180. grid-template-columns: 1fr;
  181. margin: 0 20px;
  182. }
  183. .main .main-tt .course {
  184. display: grid;
  185. grid-template-rows: 40px 1fr;
  186. grid-template-columns: 1fr;
  187. }
  188. .main .main-tt .course ul {
  189. display: grid;
  190. grid-template-rows: 1fr 1fr;
  191. grid-template-columns: repeat(3, 1fr);
  192. gap: 5px;
  193. place-items: start center;
  194. margin: 0 20px;
  195. }
  196. .main .main-tt .course ul li {
  197. margin-top: 10px;
  198. width: 170px;
  199. /* height: 160px; */
  200. background-color: #fff;
  201. /* border: red 1px solid; */
  202. }
  203. .main .main-tt .course ul li a {
  204. display: grid;
  205. grid-template-rows: 90px 50px;
  206. grid-template-columns: 1fr;
  207. }
  208. .main .main-tt .course ul li a span {
  209. background-color: #fff;
  210. position: relative;
  211. font-size: 14px;
  212. /* height: 80px; */
  213. padding: 15px;
  214. /* border-top: red 1px solid; */
  215. border-radius: 10px;
  216. top: -15px;
  217. }
  218. .main .main-tt .course ul li a span lable {
  219. padding: 3px 3px;
  220. margin: 0 3px;
  221. color: #fff;
  222. background-color: #ccc;
  223. }
  224. .main .main-tt .course ul li a img {
  225. width: 170px;
  226. height: 90px;
  227. border-radius: 10px;
  228. }
  229. .main .main-tt .manual {
  230. display: grid;
  231. grid-template-columns: 1fr;
  232. grid-template-rows: 40px 1fr;
  233. }
  234. .main .main-tt .manual ul {
  235. margin: 0 20px;
  236. display: grid;
  237. grid-template-columns: 1fr;
  238. grid-template-rows: repeat(6, 1fr);
  239. }
  240. .main .main-tt .manual ul li {
  241. display: grid;
  242. grid-template-rows: 50px;
  243. grid-template-columns: 40px 1fr;
  244. place-items: center;
  245. }
  246. /* .main .main-tt .manual ul li */
  247. .main .main-tt .manual ul li img {
  248. width: 40px;
  249. }
  250. .main .main-tt .manual ul li div {
  251. margin-left: 15px;
  252. font-size: 14px;
  253. }
  254. /*精品课程*/
  255. .main .r-course {
  256. background-color: #fff;
  257. border-radius: 10px;
  258. box-shadow: 0 4px 8px 0 #ccc;
  259. }
  260. .main .r-course h3 {
  261. padding: 25px 0;
  262. color: #6d6b6b;
  263. text-align: center;
  264. }
  265. .main .r-course h3 span {
  266. color: #1e9fff;
  267. font-size: 20px;
  268. /* font-weight: 1200; */
  269. }
  270. .main .r-course .r-body {
  271. display: grid;
  272. grid-template-columns: repeat(5, 220px);
  273. grid-template-rows: repeat(3, 170px);
  274. gap: 15px;
  275. place-content: center;
  276. padding-bottom: 20px;
  277. }
  278. .main .r-course .r-body div:first-of-type {
  279. grid-area: span 2;
  280. }
  281. .main .r-course .r-body div {
  282. box-shadow: 0 4px 8px #ccc;
  283. width: 217px;
  284. /* height: 180px; */
  285. /* background-color: violet; */
  286. border-radius: 10px;
  287. }
  288. .main .r-course .r-body div a {
  289. font-size: 14px;
  290. }
  291. .main .r-course .r-body div a span {
  292. display: block;
  293. background-color: #fff;
  294. position: relative;
  295. padding: 4px 5px;
  296. border-radius: 10px;
  297. top: -25px;
  298. }
  299. .main .r-course .r-body div a span label {
  300. background-color: #ccc;
  301. padding: 1px;
  302. margin-right: 5px;
  303. }
  304. .main .r-course .r-body div a span span {
  305. display: inline;
  306. position: relative;
  307. /* display: inline-block; */
  308. color: #93999f;
  309. font-size: 12px;
  310. top: 15px;
  311. right: -140px;
  312. }
  313. .main .r-course .r-body * img {
  314. border-radius: 10px;
  315. }
  316. .main .r-course .r-body div:not(:first-of-type) img {
  317. width: 217px;
  318. }
  319. /**/
  320. footer {
  321. height: 170px;
  322. background-color: #393d49;
  323. display: grid;
  324. grid-template-columns: 1fr 1200px 1fr;
  325. grid-template-rows: repeat(3fr);
  326. place-items: center start;
  327. }
  328. footer .link ul li {
  329. float: left;
  330. margin-top: 40px;
  331. }
  332. .link ul li a {
  333. padding: 0px 15px 0 0;
  334. color: rgb(194, 192, 192);
  335. font-size: 12px;
  336. }
  337. .link ul li a:hover {
  338. color: rgb(255, 255, 255);
  339. }
  340. footer div:first-of-type {
  341. grid-area: span 3;
  342. }
  343. footer div:nth-of-type(3) {
  344. grid-area: span 3;
  345. }
  346. footer p {
  347. color: #787d82;
  348. font-size: 11px;
  349. }

三. grid媒体查询

1.传统媒体查询:

传统媒体查询要设置每个VH区间的显示大小,页面宽度达到区间设置的视口宽度后调整页面大小

2.grid媒体查询:

grid 利用auto-fit自动填充,根本每个项目宽度来决定放多少列或行,自动适配


代码

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>grid媒体查询</title>
  7. <style>
  8. * {
  9. margin: 0;
  10. padding: 0;
  11. box-sizing: border-box;
  12. }
  13. .imgs {
  14. margin: 5em;
  15. padding: 1em;
  16. display: grid;
  17. grid-template-columns: repeat(auto-fit, minmax(10em, 1fr));
  18. grid-template-rows: repeat(auto-fit, minmax(10em, 70%));
  19. place-content: start space-evenly;
  20. gap: 1em;
  21. background-color: violet;
  22. border-radius: 10px;
  23. }
  24. .imgs img {
  25. width: 100%;
  26. border: 2px solid pink;
  27. border-radius: 20px;
  28. }
  29. </style>
  30. </head>
  31. <body>
  32. <div class="imgs">
  33. <img src="https://s3.ax1x.com/2021/01/01/rxURMD.jpg" alt="" />
  34. <img src="https://s3.ax1x.com/2021/01/01/rxURMD.jpg" alt="" />
  35. <img src="https://s3.ax1x.com/2021/01/01/rxURMD.jpg" alt="" />
  36. <img src="https://s3.ax1x.com/2021/01/01/rxURMD.jpg" alt="" />
  37. <img src="https://s3.ax1x.com/2021/01/01/rxURMD.jpg" alt="" />
  38. <img src="https://s3.ax1x.com/2021/01/01/rxURMD.jpg" alt="" />
  39. <img src="https://s3.ax1x.com/2021/01/01/rxURMD.jpg" alt="" />
  40. <img src="https://s3.ax1x.com/2021/01/01/rxURMD.jpg" alt="" />
  41. <img src="https://s3.ax1x.com/2021/01/01/rxURMD.jpg" alt="" />
  42. <img src="https://s3.ax1x.com/2021/01/01/rxURMD.jpg" alt="" />
  43. </div>
  44. </body>
  45. </html>
Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:css也可以模块化,这对于以后学习预处理非常有效
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