好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

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

查看更多关于CSS3网格布局基础知识的详细内容...

  阅读:37次