您好,欢迎来到记琴情感。
搜索
您的当前位置:首页CSS3网格布局基础知识

CSS3网格布局基础知识

来源:记琴情感


网格布局支持弹性尺寸(flex-size),这是一个很好的自适应布局技术。

弹性尺寸使用fr尺寸单位,其来自 "fraction" 或 "fractional unit" 单词的前两个字母,表示整体空间的一部分。

比如下面的CSS规则:

grid-template-columns: 100px 1fr max-content minmax(min-content, 1fr);

表示有4列,第一列100px固定尺寸,第三列 max-content 代表刚好包含元素不溢出不换行的尺寸,剩下的2列都是弹性尺寸。

按照弹性尺寸的计算规则,两者将均分(这两列的弹性系数相等,均为1)剩下的可用空间。

完整示范代码:

#grid { display: grid; width: 100%; grid-template-columns: 100px 1fr max-content minmax(min-content, 1fr);}#areaA { background-color: lime;}#areaB { background-color: yellow;}#areaC { background-color: lime;}#areaD { background-color: orange;}#areaA { background-color: green;}div { height: 80px; line-height: 80px; text-align: center;}

 Site Logo Slogan User Zone

你可以自己试试看:http://wow.techbrood.com/fiddle/15917


by iefreer

Copyright © 2019- jqzh.cn 版权所有

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务