网格布局

学习来自阮一峰老师的教程网格布局和网络上的一些资料的学习

1、定义:

顾名思义,网格布局是将页面按行(row)和列(column)划分成一个个网格来进行布局

使用方法:display:grid || inline-grid来定义一个容器为网格布局

在定义网格布局的容器里面的display:table-ceil,float,vertical-align等设置会失效
示例图:

2、容器属性:
  • grid-template-columns: 定义每一列的列宽
  • grid-template-rows: 定义每一行的行高
注意: repeat:定义重复列宽或行高 fr:定义的属性值,代指片段宽度, 2fr为1fr的两倍宽,还有auto-fill关键字,minmax()方法,auto关键字等属性
  • grid-row-gap: 定义行与行之间的间距
  • grid-column-gap: 定义列与列之间的间距
  • grid-gap: grid-row-gap grid-column-gap
  • grid-auto-flow: 定义项目的排列顺序,row(默认值,先行后列) column(先列后行) row||column + dense(类似于浮动,尽量贴紧)
  • justify-items: 定义项目中的水平位置,值:start(左) | end(右) | center(中) | stretch(默认,拉升);
  • align-items:定义项目中的垂直位置,值:start(左) | end(右) | center(中) | stretch(默认,拉升);
  • place-items: justify-items align-items
  • justify-content: 是整体(全部)项目在容器中的水平位置,值:start | end | center | stretch | space-around | space-between | space-evenly
  • align-content :是整体(全部)项目在容器中的垂直位置,值与justify-content相同
  • place-content: justify-content align-content
  • grid-auto-columns 与 grid-auto-columns 对自动创建的多余网格设置列宽和行高
3、项目属性:

grid-column||row-start||end 定位项目从哪个网线开始或截止

grid-column: grid-column-start / grid-column-end 的简写 grid-row与之一样

justify||align-self :设置单个项目的水平或垂直位置(不是全部,只设置一个)

place-self: jsutify-self align-self 简写

实例代码:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>test</title>
</head>
<style>
.main{
/*
grid: 默认为块元素
inline-grid: 默认为行内块元素
*/
display:grid;
width:400px;
height:150px;
/* 定义列宽,定义多少个就分成多少列
注意没定义行高,实际中会跟据项目自动分配行高(自动填充==默认值导致(stretch等))、
grid-template-columns: 100px 100px 100px; == repeat(3,100px);
grid-template-columns: 100px 100px 100px; == repeat(3,1fr);
*/
grid-template-columns: 100px 100px 100px;
grid-row-gap: 10px;
grid-column-gap: 10px;
justify-items: stretch;
}
.left{
background-color:lightcoral;
/* justify-self: left; */
}
.contain{
background-color:limegreen;
}
.right{
background-color:lightskyblue;
}
</style>
<body>
<!-- <span>1111</span> -->
<div class="main">
<div class="left">1</div>
<div class="contain">2</div>
<div class="right">3</div>
<div class="right">4</div>
<div class="left">5</div>
<div class="contain">6</div>
</div>
<!-- <span>2222</span> -->
</body>
</html>
总结:

不行了,看完脑子太乱了,这些语法还是等以后,做个实战来加深记录吧~~

最新文章

  1. Print a Binary Tree in Vertical Order
  2. 从零自学Hadoop(16):Hive数据导入导出,集群数据迁移上
  3. Ubuntu 设置当前用户sudo免密码
  4. javascript-this,call,apply,bind简述3
  5. notepad++之TextFX插件
  6. PHP 文件读取 fread、fgets、fgetc、file_get_contents 与 file 函数
  7. C# 中的结构类型(struct)
  8. nyoj 214
  9. YII2 实现后台操作记录日志
  10. ioS开发之CoreLocation(GPS定位)
  11. MongoDB大数据高并发读写性能测试报告
  12. SpringBoot2.0之六 多环境配置
  13. Connet Scanning
  14. git教程:工作区和暂存区
  15. 接口自动化 基于python+Testlink+Jenkins实现的接口自动化测试框架
  16. flask debug 模式开启
  17. 引入第三方SDK allowBackup value不一致引起的编译异常
  18. nginx 耗时原因定位总结
  19. awk 和 sed (Stream Editor)
  20. 理解lua中 . : self

热门文章

  1. git本地项目连接私人远程仓库以及遇到的问题
  2. c# 窗体开发3 文件处理技术
  3. Linux中docker的使用二
  4. 深入浅出-iOS程序性能优化
  5. Netty学习——Netty和Protobuf的整合(二)
  6. 《手把手教你》系列进阶篇之1-python+ selenium自动化测试 - python基础扫盲(详细教程)
  7. BZOJ1001: [BeiJing2006]狼抓兔子(优化的dinic或转化对偶图求最短路)
  8. A*算法在最短路问题的应用及其使用举例
  9. 在ASP.NET Core中使用托管启动(hosting startup)程序集,实现批量注册service
  10. docker-网络模式