Blogger Information
Blog 14
fans 2
comment 2
visits 6659
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Grid布局10大属性操作演示
西门瑶雪
Original
428 people have browsed it

Grid布局10大属性操作演示

10大属性

1、grid:创建grid容器
2、grid-template-rows/columns:显示网格单元
3、grid-area:将项目放到指定的网格单元中
4、grid-auto-flow:行与列的排序规则,默认是rows;
5、grid-auto-rows/columns:显示网格的行/列的大小
6、gap:行与列的间距,只写一个则第二个默认同第一个相同
7、place-content:所有项目在容器的对齐方式(容器元素)
8、place-items:所有项目在单元格的对齐方式(容器元素)
9、place-self:某个项目在网格单元中对齐方式(项目元素)
10、grid-row/column:行或列的跨越数量(项目元素)

图例效果

html

  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. <title>Grid布局容器框架</title>
  8. <link rel="stylesheet" href="grid.css">
  9. </head>
  10. <body>
  11. <div class="main">
  12. <div class="grd"></div>
  13. </div>
  14. <!--
  15. <style>
  16. /*
  17. 1、创建grid
  18. 2、划分网格单元
  19. */
  20. body * {
  21. outline: 1px solid rgb(221, 23, 23);
  22. }
  23. .nav{
  24. width: 30em;
  25. height: 30em;
  26. width: 40em;
  27. height: 50em;
  28. display: grid;
  29. background-color: rgb(209, 142, 142);
  30. grid-template-columns:repeat(3,10em);
  31. grid-template-rows: 10em 10em 10em;
  32. place-content: start start;
  33. place-content: center center;
  34. place-content: place-between;
  35. }
  36. .nav .sa1{
  37. background-color: blueviolet;
  38. grid-row: 2 / 3;
  39. grid-column: 2 / 3;
  40. grid-row: 2 / 4;
  41. grid-column: 2 / 4;
  42. grid-row:2 / span 2;
  43. grid-column: 2 / span 2;
  44. }
  45. .nav .sad{
  46. width: 3em;
  47. height: 3em;
  48. background-color: blueviolet;
  49. place-items: center;
  50. place-content: content;
  51. }
  52. </style>
  53. ---->
  54. </body>
  55. </html>

CSS代码演示

  1. *{
  2. margin: 0;
  3. padding: 0;
  4. box-sizing: border-box;
  5. }
  6. body * {
  7. outline: 1px solid rgb(27, 4, 4);
  8. }
  9. /*
  10. 1、创建grid
  11. 2、画格子
  12. */
  13. .main{
  14. height: 50em;
  15. width: 50em;
  16. background-color: rgb(247, 211, 8);
  17. display: grid;
  18. /*
  19. grid-template-columns: 10em 10em 10em;
  20. grid-template-rows: 10em 10em 10em;
  21. 创建格子简化用 repeat共2个参数 重复的次数,重复的值*/
  22. grid-template-rows: repeat(3,10em);
  23. grid-template-columns: repeat(3,10em);
  24. grid-auto-flow: column;
  25. grid-auto-flow: row;
  26. gap:5px 10px;
  27. gap:0px;
  28. place-content: center center;
  29. place-content: center start;
  30. place-content: start;
  31. place-content: end;
  32. place-content: space-between end;
  33. place-content: space-between;
  34. place-items: center;
  35. place-content: end;
  36. place-content: start;
  37. place-items: center;
  38. place-content: center center;
  39. }
  40. .main .grid:nth-of-type(3){
  41. place-self: end;
  42. }
  43. .main .grid{
  44. height: 5em;
  45. width: 5em;
  46. background-color: rgb(209, 178, 178);
  47. /*
  48. grid-row: 1 / 2;
  49. grid-column: 1 / 2;
  50. grid-row: 2 / 4;
  51. grid-column: 2 / 4;
  52. grid-row-start: 2;
  53. grid-column-start: 2;
  54. grid-row-end: 1;
  55. grid-column-end:3;
  56. height: 5em;
  57. width: 5em;
  58. grid-area:直接定义网格区域
  59. 有4个数值:行开始,列开始,行结束(跨越的行数),列结束(跨越的列数)
  60. */
  61. /* grid-row: 3 / span 1;
  62. grid-column: 1 / span 3;
  63. grid-area: 2 / 1 / span 1 /span 3;
  64. 新生成的项目,自动放入自动生产的单元格,并且与新单元格的宽度自适应
  65. gap 有行间距,列间距
  66. */
  67. }
Correcting teacher:PHPzPHPz

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