栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > Web开发 > Html/CSS > CSS教程

CSS3新属性之---flex box布局实例

CSS教程 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

CSS3新属性之---flex box布局实例

flex box布局实例

flex的强大之处在于不管什么布局,几行命令即可实现



骰子布局 单项目
.box {
display: flex;
justify-content: center;
justify-content: flex-end;
}
.box {
display: flex;
justify-content: center;
align-items: center;
justify-content: flex-end;
align-items: flex-end;
}
双项目
.box {
display: flex;
flex-direction: column;
justify-content: space-between;
align-items: center;
align-items: flex-end;
}

.box {
display: flex;
}
.item:nth-child(2) {
align-self: center;
}
.box {
display: flex;
justify-content: space-between;
}
.item:nth-child(2) {
align-self: flex-end;
}
三项目

.box {
display: flex;
}

.item:nth-child(2) {
align-self: center;
}

.item:nth-child(3) {
align-self: flex-end;
}

##四项目











.box {
display: flex;
flex-wrap: wrap;
align-content: space-between;
}

.column {
flex-basis: 100%;
display: flex;
justify-content: space-between;
}

##六项目

.box {
display: flex;
flex-wrap: wrap;
align-content: space-between;
}
.box {
display: flex;
flex-direction: column;
flex-wrap: wrap;
align-content: space-between;
}

##九项目

.box {
display: flex;
flex-wrap: wrap;
}

---
## 二,网格布局
### 1.基本网格(类似bootstrap实现)


...
...
...

.Grid {
display: flex;
}

.Grid-cell {
flex: 1;
}

###2.百分比布局---某个网格的宽度为固定的百分比,其余网格平均分配剩余的空间。


...
...
...

.Grid {
display: flex;
}

.Grid-cell {
flex: 1;
}

.Grid-cell.u-full {
flex: 0 0 100%;
}

.Grid-cell.u-1of2 {
flex: 0 0 50%;
}

.Grid-cell.u-1of3 {
flex: 0 0 33.3333%;
}

.Grid-cell.u-1of4 {
flex: 0 0 25%;
}

### 3.圣杯布局---(Holy Grail Layout)一种最常见的网站布局


...


...


...

...


/适应小屏幕/
@media (max-width: 768px) {
.HolyGrail-body {
flex-direction: column;
flex: 1;
}
.HolyGrail-nav,
.HolyGrail-ads,
.HolyGrail-content {
flex: auto;
}
}
.HolyGrail {
display: flex;
min-height: 100vh;
flex-direction: column;
}

header,
footer {
flex: 1;
}

.HolyGrail-body {
display: flex;
flex: 1;
}

.HolyGrail-content {
flex: 1;
}

.HolyGrail-nav, .HolyGrail-ads {
/ 两个边栏的宽度设为12em /
flex: 0 0 12em;
}

.HolyGrail-nav {
/ 导航放到最左边 /
order: -1;
}

### 4.输入框布局---前提示后按钮


...



.InputAddOn {
display: flex;
}
.InputAddOn-field {
flex: 1;
}

### 5.悬挂布局---主栏的左侧或右侧,需要添加一个图片栏



...



.Media {
display: flex;
align-items: flex-start;
}

.Media-figure {
margin-right: 1em;
}
.Media-figure {
margin-right: 1em;
}

.Media-body {
flex: 1;
}

###6. 固定低栏


...

...

...


.Site {
display: flex;
min-height: 100vh;
flex-direction: column;
}
.Site-content {
flex: 1;
}

###7. 流式布局---列数固定自动分行

.parent {
width: 200px;
height: 150px;
background-color: black;
display: flex;
flex-flow: row wrap;
align-content: flex-start;
}

.child {
box-sizing: border-box;
background-color: white;
flex: 0 0 25%;
height: 50px;
border: 1px solid red;
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/243285.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号