搜索
博主信息
博文 40
粉丝 0
评论 1
访问量 31322
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
第13章 1225-grid实战,学习心得、笔记
努力工作--周工--Robin
原创
634人浏览过

今天所学心得、笔记

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属性,自适应调整“列”的数量,从而调整页面布局;
批改老师:天蓬老师天蓬老师

批改状态:合格

老师批语:严格来说,grid那个不叫媒体查询,顶多是响应式布局
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学