Flex and Grid Layout Evancohe 2021-03-21 Flex横向: 1234567891011display: flex 声明使用flex box布局flex-direction : row方向flex-wrap 是否换行justify-content 横排版align-items: 竖排版align-content: 间距 竖向: 12345678910111213141516171819202122232425flex-direction : column 元素竖向justify-content 竖排版 (与direction横向相反)align-items: 横排版 (与direction横向相反)其他:快捷写法:flex: 1 0 0px > 1 : flex-grow> 0 : flex-shink> 0px: flex-basisflex-grow: 1 最后一个元素如果有空位会填满 (0.5则一半)flex-shink: 0 元素不会随页面大小自行缩放flex-basis: 0 无视width, 设置成grow具体数值order: 2 改变到2位置(不推荐使用, 对阅读器用户不友好) Grid12345678910111213141516171819202122display: grid 定义grid-template-columns: 1fr 1fr 1fr 1fr 定义横向 4个相同的块grid-template-rows: 1fr 1fr 1fr 1fr 定义竖向 4个相同的块grid-gap: 每个元素间的间距grid-template-areas: 'grid-item-1 grid-item-1 grid-item-1 grid-item-1''grid-item-2 grid-item-3 grid-item-3 grid-item-3''grid-item-2 grid-item-4 grid-item-4 grid-item-5''grid-item-2 grid-item-6 grid-item-6 grid-item-6';每个元素需要定义area,如:grid-area: grid-item-6;