Blogger Information
Blog 46
fans 2
comment 0
visits 19485
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
grid属性
P粉314265155
Original
361 people have browsed it

创建grid容器,进行行;列及跨行跨列排列

  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  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. <style>
  9. .box{
  10. display: grid;
  11. border: 2px solid rebeccapurple;
  12. border-color: aqua;
  13. background-color: blue;
  14. width: 30em;
  15. height: 30em;
  16. grid-template-columns: 10em 10em 10em ;
  17. grid-template-rows: 10em 10em 10em;
  18. /* grid-template-columns: repeat(3, 10em);
  19. grid-template-rows: repeat(3, 10em); */
  20. }
  21. .box > .box1{
  22. /* 注意跨行列时,将项目宽度高度去掉,不然不生效 */
  23. /* width: 5em;
  24. height: 5em; */
  25. background-color: black;
  26. color: brown;
  27. /* grid-row-start: 2 ;
  28. grid-row-end: 3;
  29. grid-column-start: 3;
  30. grid-column-end: 3;
  31. grid-row: 2 ;
  32. grid-column: 3;
  33. grid-row: 1 / 2;
  34. grid-column: 2/3; */
  35. grid-row: 2 / span2;
  36. grid-column: 2 / span 4;
  37. grid-row: 2 / span 2;
  38. grid-row: 3 / span1;
  39. grid-row: 2 / span2;
  40. grid-column: 2 / span2;
  41. grid-row: 3 / span1;
  42. /* 简化 grid-row: 3 span1是默认的 */
  43. grid-column: 1 / span3;
  44. /*grid-area: ; 直接定义网格区域
  45. 行开始、列开始、航结束、列结束
  46. */
  47. grid-area: 2 / 2 / span2 / span2 ;
  48. }
  49. </style>
  50. </head>
  51. <body>
  52. <div class="box">
  53. <div class="box1">123456789</div>
  54. </div>
  55. </body>
  56. </html>

  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  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. <style>
  9. .box {
  10. display: grid;
  11. background-color: aliceblue;
  12. width: 30em;
  13. height: 30em;
  14. /* 注意repeat 括弧里面加逗号 */
  15. grid-template-columns: repeat(3 10em);
  16. /* grid-template-rows: repeat(2 100px); */
  17. grid-template-rows: repeat(3, 10em);
  18. grid-template-columns: 10em 10em 10em ;
  19. /* 行的意思 创建3行 每行 宽度10个em */
  20. grid-template-rows: 10em 10em 10em ;
  21. grid-template-columns: repeat(3, 10em);
  22. grid-template-rows: repeat(3, 10em);
  23. /* 默认行排列 */
  24. grid-auto-flow: row;
  25. /* 可以列排列 */
  26. grid-auto-flow: column;
  27. /* 默认自动排列填充 */
  28. /* grid-auto-rows: auto; */
  29. /* 容器中的列宽 只有两个值上下 左右 */
  30. gap: 1em 1em ;
  31. /* place-content剩余空间 容器剩余空间的对齐
  32. 两个值第一个垂直第二个水平
  33. */
  34. place-content: center end;
  35. place-content: center center;
  36. place-content: center;
  37. place-content: center start;
  38. /* 所有剩余空间还可以在项目之间进行分配 也是两个值 */
  39. place-content: space-between space-around;
  40. place-content: space-between space-between;
  41. place-content: space-between;
  42. /* place-items项目在网格单元中的对齐方式 也是两个值 */
  43. place-items: center;
  44. place-items: start end;
  45. }
  46. .box > .box1{
  47. background-color: blue;
  48. width: 5em;
  49. height: 5em;
  50. }
  51. </style>
  52. </head>
  53. <body>
  54. <div class="box">
  55. <div class="box1">item1</div>
  56. <div class="box1">item2</div>
  57. <div class="box1">item3</div>
  58. <div class="box1">item4</div>
  59. <div class="box1">item5</div>
  60. <div class="box1">item6</div>
  61. <div class="box1">item7</div>
  62. <div class="box1">item8</div>
  63. <div class="box1">item9</div>
  64. <div class="box1">item10</div>
  65. <div class="box1">item11</div>
  66. </div>
  67. </body>
  68. </html>

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!