弹性尺寸使用 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
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did110702