时间:2021-07-01 10:21:17 帮助过:56人阅读
弹性尺寸使用fr尺寸单位,其来自 "fraction" 或 "fractional unit" 单词的前两个字母,表示整体空间的一部分。
比如下面的CSS规则:
- grid-template-columns: 100px 1fr max-content minmax(min-content, 1fr);
表示有4列,第一列100px固定尺寸,第三列 max-content 代表刚好包含元素不溢出不换行的尺寸,剩下的2列都是弹性尺寸。
按照弹性尺寸的计算规则,两者将均分(这两列的弹性系数相等,均为1)剩下的可用空间。
CSS3示范代码:
- #grid {
- display: grid;
- width: 100%;
- grid-template-columns: 100px 1fr max-content minmax(min-content, 1fr);
- }
- #title {
- background-color: lime;
- }
- #score {
- background-color: yellow;
- }
- #stats {
- background-color: lime;
- }
- #message {
- background-color: orange;
- }
- p {
- height: 80px;
- line-height: 80px;
- text-align: center;
- }
HTML代码:
- <p id="grid">
- <p id="title">Site Logo</p>
- <p id="score">Slogan</p>
- <p id="stats">User Zone</p>
- <p id="message">Message</p>
- </p>
相关推荐:
css3弹性布局
以上就是CSS3自适应布局技术之弹性尺寸的详细内容,更多请关注Gxl网其它相关文章!