博客列表 >第13章 1225-grid实战,学习心得、笔记

第13章 1225-grid实战,学习心得、笔记

努力工作--周工--Robin
努力工作--周工--Robin原创
2021年01月20日 11:55:18486浏览

今天所学心得、笔记

1、网格单元和容器中对齐的相关属性全部实例演示

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

  1. <style>
  2. /*初始化*/
  3. * {
  4. margin: 0;
  5. padding: 0;
  6. box-sizing: border-box;
  7. }
  8. li {
  9. list-style: none;
  10. }
  11. .container {
  12. display: grid;
  13. border: 1px solid;
  14. width: 35em;
  15. height: 35em;
  16. grid-template-columns: repeat(4, 1fr);
  17. grid-template-rows: repeat(4, 1fr);
  18. gap: .5em;
  19. }
  20. .container .item {
  21. width: 3.5em;
  22. height: 3.5em;
  23. border: 1px solid;
  24. background-color: pink;
  25. text-align: center;
  26. line-height: 3em;
  27. }
  28. /*项目网格对齐*/
  29. .container {
  30. /*左上角*/
  31. place-items: start start;
  32. /*右上角*/
  33. place-items: start right;
  34. /*左下角*/
  35. place-items: end left;
  36. /*右下角*/
  37. place-items: end right;
  38. /*正中*/
  39. place-items: center center;
  40. /*正中,简写*/
  41. place-items: center;
  42. }
  43. /*10号项目,单独上右对齐*/
  44. .container .item:nth-of-type(13),
  45. .container .item:nth-of-type(10),
  46. .container .item:nth-of-type(7),
  47. .container .item:nth-of-type(4)
  48. {
  49. place-self: start right;
  50. }
  51. </style>

项目在网格容器中的对齐方式

  1. <style>
  2. .container {
  3. width: 35em;
  4. height: 35em;
  5. border: 1px solid;
  6. display: grid;
  7. grid-template-columns: repeat(4, 5em);
  8. grid-template-rows: repeat(4, 5em);
  9. gap: .5em;
  10. /*项目在网格单元中对齐*/
  11. place-items: center;
  12. }
  13. .container .item {
  14. width: 3.5em;
  15. height: 3.5em;
  16. background-color: pink;
  17. text-align: center;
  18. line-height: 3.5em;
  19. }
  20. /*项目在网格容器中对齐*/
  21. .container {
  22. /*上左*/
  23. place-content: start left;
  24. place-content: start;
  25. /*上右*/
  26. place-content: start right;
  27. /*下左*/
  28. place-content: end left;
  29. /*下右*/
  30. place-content: end right;
  31. place-content: end;
  32. /*居中*/
  33. place-content: center;
  34. /*--------------------------------------------*/
  35. /*两端对齐*/
  36. place-content: space-between;
  37. /*元素上下左右,四边剩余空间相等*/
  38. place-content: space-around;
  39. /*剩余空间平均分配*/
  40. place-content: space-evenly;
  41. /*元素上下剩余空间相等,左右空间剩余平均分配*/
  42. place-content: space-around space-evenly;
  43. }
  44. </style>

2、快速实现php.cn首页主要组件的布局

示例截图

" class="reference-link">

3、理解grid的媒体查询与专业的媒体查询有什么区别?

  1. 个人理解如下,不知对不对:
  2. 1、专业媒体查询,是通过系统监视浏览器窗口的大小,根据设定的阀值来调整html元素字号的大小,从而调整页面布局;
  3. 2、grid的媒体查询,是通过auto-fit属性,自适应调整“列”的数量,从而调整页面布局;
声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议