Blogger Information
Blog 41
fans 0
comment 0
visits 30981
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Grid网格布局的项目属性及php中文网实例
陈强
Original
554 people have browsed it

项目属性

项目在单元中的对齐方式

  • place-items: 所有项目在网格单元中的对齐方式-垂直方向 水平方向
  1. /* 垂直-居上 水平-居中 */
  2. place-items: start center;
  3. /* 垂直-居中 水平-居中 */
  4. place-items: center center;
  5. /* 如果垂直和水平属性值一样可以简写 */
  6. place-items: center;
  • plce-sele: 某一个项目在网络单元中的对齐方式
  1. /* 设置某一项目的对齐方式,必须在项目上设置 */
  2. .container .item:nth-of-type(5) {
  3. /* 垂直-居上 水平-居右 */
  4. place-self: start end;
  5. }
  6. /* 设置某一项目在单元格或网格区域中的对齐方式 */
  7. .container .item:nth-of-type(3) {
  8. /* 跨越两行两列垂直居下,水平居右显示 */
  9. grid-area: span 2 / span 2;
  10. place-self: end;
  11. }

1.项目在网格单元中是拉伸的
2.只有项目在网络单元中存在剩余空间的时候,对齐才有必要且有意义

项目在容器中的对齐方式

  • 将项目在网格容器中看做一个整体的对齐方式
  1. /* 所有项目在垂直居下,水平居右显示 */
  2. place-content: end end;
  • 将项目看到独立个体的对齐方式
  1. /* 所有项目在垂直上下两端居中,水平左右两端对齐居中显示 */
  2. place-content: space-between space-between;

php中文网案例

  • html代码
  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>Document</title>
  7. <link rel="stylesheet" href="css/style.css" />
  8. </head>
  9. <body>
  10. <header>
  11. <div class="logo">
  12. <a href="/"><img src="https://www.php.cn/static/images/logo.png" alt="" /></a>
  13. </div>
  14. <div class="nav">
  15. <ul>
  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="#">技术文章</a></li>
  21. <li><a href="#">资源下载</a></li>
  22. <li><a href="#">编程词典</a></li>
  23. <li><a href="#">工具下载</a></li>
  24. <li><a href="#">php培训</a></li>
  25. </ul>
  26. </div>
  27. <div class="login">
  28. <div class="voice">
  29. <img src="" alt="" />
  30. </div>
  31. <div class="user">
  32. <img src="https://img.php.cn/upload/avatar/000/000/001/153c595e8fe1b269ec2b40414760a424.jpg" alt="" />
  33. </div>
  34. </div>
  35. </header>
  36. <main>
  37. <ul class="aside-left">
  38. <li><a href="">php开发</a><i></i></li>
  39. <li><a href="">前端开发</a><i></i></li>
  40. <li><a href="">服务端开发</a><i></i></li>
  41. <li><a href="">移动开发</a><i></i></li>
  42. <li><a href="">数据库</a><i></i></li>
  43. <li><a href="">服务器运维</a><i></i></li>
  44. <li><a href="">在线工具箱</a><i></i></li>
  45. <li><a href="">常用库类</a><i></i></li>
  46. </ul>
  47. <ul class="top">
  48. <li><a href="">php头条</a></li>
  49. <li><a href="">独孤九剑</a></li>
  50. <li><a href="">学习路线</a></li>
  51. <li><a href="">在线工具</a></li>
  52. <li><a href="">趣味课堂</a></li>
  53. <li><a href="">社区问答</a></li>
  54. <li><a href="">课程直播</a></li>
  55. <li><input type="text" placeholder="输入关键词搜索" /></li>
  56. </ul>
  57. </div>
  58. <div class="silder">
  59. <a href="">
  60. <img src="https://img.php.cn/upload/article/000/000/001/5fb478a8e82cb116.jpg" alt="" />
  61. </a>
  62. </div>
  63. <ul class="show">
  64. <li>
  65. <a href="">
  66. <img src="https://www.php.cn/static/images/index_yunv.jpg" alt="" />
  67. </a>
  68. </li>
  69. <li>
  70. <a href="">
  71. <img src="https://www.php.cn/static/images/index_php_item2_.png?1" alt="" />
  72. </a>
  73. </li>
  74. <li>
  75. <a href="">
  76. <img src="https://www.php.cn/static/images/index_php_item3.jpg?1" alt="" />
  77. </a>
  78. </li>
  79. <li>
  80. <a href="">
  81. <img src="https://www.php.cn/static/images/index_php_new4.jpg?1" alt="" />
  82. </a>
  83. </li>
  84. </ul>
  85. </main>
  86. <footer></footer>
  87. </body>
  88. </html>
  • css样式表
  1. * {
  2. margin: 0;
  3. padding: 0;
  4. box-sizing: border-box;
  5. }
  6. a {
  7. color: #333;
  8. text-decoration: none;
  9. display: block;
  10. }
  11. img {
  12. width: 100%;
  13. }
  14. ul li {
  15. list-style: none;
  16. }
  17. body {
  18. background-color: #f3f5f7;
  19. font: 14px Helvetica Neue, Helvetica, PingFang SC, \5fae\8f6f\96c5\9ed1, Tahoma, Arial, sans-serif;
  20. }
  21. header {
  22. display: grid;
  23. grid-template-columns: 1fr 9fr 1fr;
  24. background-color: #000;
  25. }
  26. header .nav {
  27. display: grid;
  28. }
  29. header .logo {
  30. width: 8em;
  31. }
  32. header .nav ul {
  33. display: grid;
  34. grid-template-columns: repeat(10, 1fr);
  35. place-items: center;
  36. gap: 1em;
  37. }
  38. header .nav a {
  39. color: #fff;
  40. }
  41. header .login {
  42. display: grid;
  43. grid-template-columns: 1fr 1fr;
  44. place-items: center;
  45. }
  46. header .login .user {
  47. height: 2em;
  48. width: 2em;
  49. border-radius: 100%;
  50. overflow: hidden;
  51. }
  52. main {
  53. display: grid;
  54. grid-template-columns: 15em 1fr;
  55. grid-template-rows: 4em 1fr 8em;
  56. max-width: 80vw;
  57. margin: 0 auto;
  58. margin-top: 2em;
  59. }
  60. main .aside-left {
  61. grid-area: span 3;
  62. background-color: #2b333b;
  63. }
  64. main .aside-left {
  65. padding-left: 2em;
  66. }
  67. main .aside-left li {
  68. display: grid;
  69. grid-template-columns: 4fr 1fr;
  70. height: 64px;
  71. line-height: 64px;
  72. }
  73. .aside-left i::after {
  74. content: " ";
  75. display: inline-block;
  76. height: 0.6em; /*height、width控制箭头大小*/
  77. width: 0.6em;
  78. border-width: 2px 2px 0 0;
  79. border-color: #999;
  80. border-style: solid;
  81. -webkit-transform: matrix(-0.71, 0.71, 0.71, 0.71, 0, 0);
  82. /*前面四个参数控制箭头方向 最后两个参数分别控制距离左侧的距离 距离上侧的距离*/
  83. transform: matrix(0.71, -0.71, -0.71, -0.71, 6, 1);
  84. }
  85. main .aside-left a {
  86. color: #999;
  87. }
  88. main .top {
  89. display: grid;
  90. place-items: center start;
  91. background-color: #fff;
  92. padding-left: 1em;
  93. }
  94. main .top {
  95. display: grid;
  96. grid-template-columns: repeat(7, 5em) 1fr;
  97. gap: 1em;
  98. }
  99. main .show {
  100. background-color: #fff;
  101. }
  102. main .show {
  103. display: grid;
  104. grid-template-columns: repeat(4, 1fr);
  105. gap: 1em;
  106. place-items: center;
  107. }
  108. main .show img {
  109. border-radius: 0.5em;
  110. }
  • 效果截图

Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:有空可看看更多属性介绍(mdn)
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