GFC?一篇管饱(display:grid)
GFC
GFC全称是**gridLavoutformatting context.**他就是网格布局格式上下文,是用于布局网格容器的一-块渲染区域。
其实把display设置为grid后,这个盒子就成了grid布局
div{display:grid;
}
flex布局好用吧?这个grid布局可是flex Plus !!!
赶紧来试试
用grid实现9宫格
<html>
<head>
<style>.box{display:grid;grid-template-columns: auto auto auto;grid-template-rows:auto auto auto;grid-gap:10px;height:800px;background-color:#00ffff;}.a{background-color:yellow;}
</style>
<head>
<body><div class='box'><div class='a'>1</div> /* 来9个 */</div>
<body>
</html>
grid布局常用属性
- grid: 1fr 1fr 1fr/1fr 1fr 1fr ; 高度 高度 高度/(一)列 (二)列 (三) 列
grid: 100px 200px 100px /1fr 1fr 1fr;
// 等同于
grid-template-rows: 100px 200px 100px;
grid-template-columns: 1fr 1fr 1fr;
grid-template-areas: none;
grid-auto-flow: initial;
grid-auto-rows: initial;
grid-auto-columns: initial;
grid-template-columns: 100px 100px; //有几列,每列有多大
grid-template-rows :100px 100px; //有几行,每行有多大
grid-template: [] '1 1 1' 100px [] /auto 50px auto;
//[名称] '几列' 这行的高度 [名称] /三列对应的三个宽度
//(名称可为空 '1 1 1' 就是均分三列)
grid-gap: 10px 20px ;//上下间隔10px,左右间隔20px
grid-gap: 10px;//上下左右间隔10px
grid-column-gap:10px; // 上下间隔10px
grid-row-gap:10px; // 左右间隔10px
属性 : justify-items
justify-items:start; // 将内容对齐到网格区域(grid area)的左侧
justify-items:end; // 将内容对齐到网格区域的右侧
justify-items:center; // 将内容对齐到网格区域的中间(水平居中)
justify-items:stretch; // 填满网格区域宽度(默认值)
属性 : align-items:
justify-items:start; // 将内容对齐到网格区域(grid area)的顶部
justify-items:end; // 将内容对齐到网格区域的底部
justify-items:center; // 将内容对齐到网格区域的中间(垂直居中)
justify-items:stretch; // 填满网格区域高度(默认值)
属性 :justify-content:
justify-content:start; // 将网格对齐到 网格容器(grid container) 的顶部
justify-content:end; // 将网格对齐到 网格容器 的底部
justify-content:center; // 将网格对齐到 网格容器 的中间(垂直居中)
justify-content:stretch; // 调整 网格项(grid items) 的高度,允许该网格填充满整个 网格容器 的高度
justify-content:space-around; // 在每个网格项之间放置一个均匀的空间,左右两端放置一半的空间
justify-content:space-between; // 在每个网格项之间放置一个均匀的空间,左右两端没有空间
justify-content:space-evenly; // 在每个栅格项目之间放置一个均匀的空间,左右两端放置一个均匀的空间
属性align-content
align-content:start; // 将网格对齐到 网格容器(grid container) 的顶部
align-content:end; // 将网格对齐到 网格容器 的底部
align-content:center; // 将网格对齐到 网格容器 的中间(垂直居中)
align-content:stretch; // 调整 网格项(grid items) 的高度,允许该网格填充满整个 网格容器 的高度
align-content:space-around; // 在每个网格项之间放置一个均匀的空间,上下两端放置一半的空间
align-content:space-between; // 在每个网格项之间放置一个均匀的空间,上下两端没有空间
align-content:space-evenly; // 在每个栅格项目之间放置一个均匀的空间,上下两端放置一个均匀的空间
再来看一下MDN网站的一个案例
<style>#page {display: grid;width: 100%;height: 200px;grid-template: [header-left] "head head"30px [header-right] [main-left] "nav main"1fr [main-right] [footer-left] "nav foot"30px [footer-right] / 120px 1fr;}header {background-color: lime;grid-area: head;}nav {background-color: lightblue;grid-area: nav;}main {background-color: yellow;grid-area: main;}footer {background-color: red;grid-column: foot;}
</style><body><section id="page"><header>Header</header><nav>Navigation</nav><main>Main area</main><footer>Footer</footer></section>
</body>
GFC?一篇管饱(display:grid)相关推荐
- CSS3中的display:grid网格布局介绍
1.网格布局(grid): 它将网页划分成一个个网格,可以任意组合不同的网格,做出各种各样的布局; 2.基本概念: 容器和项目,如图所示: <div class="content&qu ...
- display:grid 布局实现两行两列
display:grid 布局实现两行两列,如图效果: 下面展示一些 内联代码片. // A code block div容器部分 // An highlighted block<div cla ...
- css display: grid属性grid-template-areas
<style> .container {border:none;display: grid;height: 600px;grid-template-columns: 200px 1fr; ...
- 前端提升篇之flex或grid布局实现多列均分布局
1 使用flex布局实现多列均分布局 首先提供一个使用弹性盒布局的多列均分布局终极解决方案,能够实现下图的效果: 其特点有: 列数可控 子元素的宽度相同 列和列之间有空隙,左右两边对齐(没有空隙) 子 ...
- display:grid 网格布局的基础使用
css新特性--网格布局 我们通过在元素上声明 display:grid 来创建一个网格容器.一旦我们这样做,这个元素的所有直系子元素将成为网格元素. 它将元素分割成行与列,通过栅格栏的形式弥补了fl ...
- display: grid的用法
.content-box {display: grid;grid-template-columns: 2fr 2.5fr 5fr 3fr 2fr;/* 用于设置列间距 */grid-column-ga ...
- display:grid的一些笔记
display: grid;grid-template-columns: repeat(3, 1fr); /* 相当于 1fr 1fr 1fr */grid-template-rows: repeat ...
- css display: grid属性repeat
.container {display: grid;box-shadow: 0 0 1px #cccccc;grid-template-columns: repeat(3,1fr); /*相当于 1f ...
- 网格布局-display:grid
一,网格布局的概念,和flex布局的区别 含义: 它将网页划分成一个个网格,可以任意组合不同的网格,做出各种各样的布局 区别: Grid布局与Flex布局有一定的相似性,都可以指定容器内多个项目的位置 ...
最新文章
- 扬州市大学计算机专业录取分数线,“计算机网络技术”专业录取分数线
- ECCV18 Oral | MIT谷歌视频运动放大让计算机辅助人眼“明察秋毫”
- 15个超实用的php正则表达式
- SpringBoot使用Gradle构建war包
- 训练softmax分类器实例_知识蒸馏:如何用一个神经网络训练另一个神经网络
- redis pub/sub 聊天
- Dos下删除(非)空目录或文件
- 移植wpa_supplicant 2.5 实现rtl8188可以无线上网
- linux界面唤醒,Linux计算机实现自动唤醒和关闭的方法步骤详解
- 开发环境配置(netbeans+ant迁移到eclipse+maven)
- MyBatis学习笔记(4)-resultMap多对多映射使用总结
- (1)、win10 本地 安装 rabbitmq
- Linux目录结构、bash的基础命令学习
- 加载八叉树索引文件_mysql innodb索引原理
- STM32与XY12864屏幕(ST7920中文显示模块)
- python机器学习实例
- Python(初学者):调用函数输出
- m3u8流媒体下载 swift
- Vue为啥可以成为2019年的一匹黑马?
- Conda更新或安装包时出现Verifying transaction: failed+RemoveError的解决方法