CSS3网格布局基础知识

WBOY
Release: 2016-06-24 11:29:03
Original
1713 people have browsed it

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

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

比如下面的CSS规则:

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

表示有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;}
Copy after login

<div id="grid">    <div id="title">Site Logo</div>    <div id="score">Slogan</div>    <div id="stats">User Zone</div>
</div>
Copy after login

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


by iefreer


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!