flex常用布局
公共样式:
<style>
* {
margin: 0;
padding: 0;
} .has-flex {
display: flex;
}
</style>
垂直居中 子元素左右分布
css
.father-one {
width: 100%;
height: 200px;
background-color: #fffcef;
align-items: center; /*纵轴)方向上的对齐方式。*/
justify-content: space-between; /* 均匀排列每个元素 首个元素放置于起点,末尾元素放置于终点,中间元素的中间间隔相等 */
justify-content: space-around; /* 均匀排列每个元素 每个元素周围分配相同的空间 */
justify-content: space-evenly; /* 均匀排列每个元素 每个元素之间的间隔相等 */
}
.fa-one-child1 {
height: 30px;
width: 30px;
background-color: #a6acde;
}
.fa-one-child2 {
height: 40px;
width: 40px;
background-color: #e4b9f0;
}
.fa-one-child3 {
height: 50px;
width: 50px;
background-color: #f3b009;
}
.fa-one-child4 {
height: 60px;
width: 60px;
background-color: #f77c4f;
}
html
<!--垂直居中 子元素左右分布 star-->
<h3>垂直居中 子元素左右分布</h3>
<div class="father-one has-flex">
<div class="fa-one-child1"></div>
<div class="fa-one-child2"></div>
<div class="fa-one-child3"></div>
<div class="fa-one-child4"></div>
</div>
<!--垂直居中 子元素左右分布 end-->

水平垂直居中
css
.father-two {
width: 100%;
height: 200px;
align-items: center; /*纵轴)方向上的对齐方式。*/
justify-content: center; /* 横轴)方向上的对齐方式*/
background-color: red;
}
.child {
width: 50%;
height: 60px;
background-color: rosybrown;
}
html
<!--水平垂直居中 star-->
<h3>水平垂直居中</h3>
<div class="father-two has-flex">
<div class="child"></div>
</div>
<!--水平垂直居中 end-->

水平垂直居中 图标在上文字在下
css
.father-three {
height: 80px;
background-color: #f77c4f;
align-items: center;
justify-content: center;
flex-direction: column;
}
html
<!--水平垂直居中 图标在上文字在下 star-->
<h3>水平垂直居中 图标在上文字在下</h3>
<div class="has-flex father-three">
<i class="fa fa-file-text-o" aria-hidden="true"></i>
<p>测试</p>
</div>
<!--水平垂直居中 图标在上文字在下 end-->

子元素平分父元素,且自适应等高
css
.father-four {
background-color: #ffd5eb;
}
.fa-four-child {
flex: 1;
text-align: center;
background-color: #ffffff;
border: 1px solid;
}
html
<!--子元素平分父元素,且自适应等高 star-->
<h3>子元素平分父元素,且自适应等高 </h3>
<div class="has-flex father-four">
<div class="fa-four-child">第一个</div>
<div class="fa-four-child">第二个</div>
<div class="fa-four-child">第三个</div>
<div class="fa-four-child" style="height: 90px">第四个</div>
</div>
<!--子元素平分父元素,且自适应等高 end-->

子元素平分父元素,两边对齐中间自适应相同宽度间隔,且自动换行
css
.father-five {
height: 100px;
background-color: #a6acde;
justify-content: space-between;
flex-wrap: wrap;
}
.fa-five-child {
width: 21%;
background-color: #f77c4f;
}
html
<!--子元素平分父元素,两边对齐中间自适应相同宽度间隔,且自动换行 star-->
<h3>子元素平分父元素,两边对齐中间自适应相同宽度间隔,且自动换行 </h3>
<div class="has-flex father-five">
<div class="fa-five-child">第一个</div>
<div class="fa-five-child">第二个</div>
<div class="fa-five-child">第三个</div>
<div class="fa-five-child">第四个</div>
<div class="fa-five-child">第五个</div>
<div class="fa-five-child">第六个</div>
<div class="fa-five-child">第七个</div>
<div class="fa-five-child">第八个</div>
</div>
<!--子元素平分父元素,两边对齐中间自适应相同宽度间隔,且自动换行 end-->

三栏布局,两边固定宽中间自适应
css
.father-six {
height: 100px;
}
.one-child,
.three-child {
width: 300px;
background-color: #a6acde;
}
.two-child {
flex: 1;
background-color: #eeeeee;
}
html
<!--三栏布局,两边固定宽中间自适应 star-->
<h3>三栏布局,两边固定宽中间自适应 </h3>
<div class="has-flex father-six">
<div class="fa-six-child one-child">第一个</div>
<div class="fa-six-child two-child">第二个</div>
<div class="fa-six-child three-child">第三个</div>
</div>
<!--三栏布局,两边固定宽中间自适应 end-->

对于Flex 布局更详细的讲解请移步:Flex 布局教程:语法篇
相关css面试题:两边宽度已知,如何让中间自适应
flex常用布局的更多相关文章
- Flex 常用布局
1.flex布局 1.1 容器指定为flex布局 .box{display: flex;} 1.2 行元素指定flex布局 .box{display:inline-flex} 2.容器的属性 2.1 ...
- CSS3动画属性和flex弹性布局各个属性
[CSS3动画的使用] 1.声明一个关键帧(动画): @keynames name{ from{} to{} } 每个阶段的写法: ①可以直接使用from-to的写法 ②可以设置0%-100%的写法, ...
- ExtJs常用布局--layout详解(含实例)
序言: 笔者用的ExtJs版本:ext-3.2.0 ExtJs常见的布局方式有:border.form.absolute.column.accordion.table.fit.card.anchor ...
- Flutter常用布局组件
Flutter控件本身通常由许多小型.单用途的控件组成,结合起来产生强大的效果,例如,Container是一种常用的控件,由负责布局.绘画.定位和大小调整的几个控件组成,具体来说,Container是 ...
- 2021年3月-第02阶段-前端基础-Flex 伸缩布局-移动WEB开发_流式布局
移动web开发流式布局 1.0 移动端基础 1.1 浏览器现状 PC端常见浏览器:360浏览器.谷歌浏览器.火狐浏览器.QQ浏览器.百度浏览器.搜狗浏览器.IE浏览器. 移动端常见浏览器:UC浏览器, ...
- CSS弹性盒模型flex在布局中的应用
× 目录 [1]元素居中 [2]两端对齐 [3]底端对齐[4]输入框按钮[5]等分布局[6]自适应布局[7]悬挂布局[8]全屏布局 前面的话 前面已经详细介绍过flex弹性盒模型的基本语法和兼容写法, ...
- python:页面布局 后台管理页面之常用布局
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...
- 常用布局,div竖直居中
常用两列布局,多列布局和div竖直居中 body { margin:; padding:; } .w200 { width: 200px; } .mar-left200 { margin-left: ...
- 跟我学android-android常用布局介绍
在上一章我们曾经谈到,Android平台的界面 是使用XML的方式设计的,然后在上一章我们只做了一个简单的界面,在这章,我们将介绍如何使用常用的控件设计实用的界面. Android中的视图都是继承Vi ...
随机推荐
- 理解 Python 的 for 循环
在本篇博客中,我们将讨论 Python 中 for 循环的原理. 我们将从一组基本例子和它的语法开始,还将讨论与 for 循环关联的 else 代码块的用处. 然后我们将介绍迭代对象.迭代器和迭代器协 ...
- C#实现一个万物皆可排序的队列
需求 产品中需要向不同的客户推送数据,原来的实现是每条数据产生后就立即向客户推送数据,走的的是HTTP协议.因为每条数据都比较小,而数据生成的频次也比较高,这就会频繁的建立HTTP连接,而且每次HTT ...
- charles(CA证书)的app端安装
在使用charles进行的app抓包的时候势必需要对他进行配置: 1. pc端: 第一步: http请求接收charles > proxy > proxy setting > por ...
- linux firewall (marker)
查看防火墙是否开启systemctl status firewalld 若没有开启则是开启状态systemctl start firewalld 关闭则start改为stop 查看所有开启的端口fi ...
- 数据库持久化+JDBC数据库连接
数据持久化 数据持久化就是将内存中的数据模型转换为存储模型,以及将存储模型转换为内存中的数据模型的统称.数据模型可以是任何数据结构或对象模型,存储模型可以是关系模型.XML.二进制流等. 瞬时状态 保 ...
- 9.2 DAG上的动态规划
在有向无环图上的动态规划是学习动态规划的基础,很多问题都可以转化为DAG上的最长路,最短路或路径计数问题 9.2.1 DAG模型 嵌套矩形问题: 矩形之间的可嵌套关系是一种典型的二元关系,二元关系可以 ...
- 精心总结十三条建议,帮你创建更合适的MySQL索引
上篇文章讲到使用MySQL的Explain命令可以分析SQL性能瓶颈,优化SQL查询,以及查看是否用到了索引. 我们都知道创建索引可以提高查询效率,但是具体该怎么创建索引? 哪些字段适合创建索引? 哪 ...
- 协程 && 异步例子
# 异步redis # 在使用python代码操作redis的时候,连接.操作.断开都是网络IO. # 安装aioredis模块: pip install aioredis==1.3.1 # 例: 该 ...
- playwright录制脚本
我喜欢Playwright! 这是微软开源的一款非常强大的自动化工具,再过几年,他很有可能取代Selenium在浏览器自动化的通知地位.使用过一段时间,我没有找到很好的中文资料可以参考,导致很多问题无 ...
- cmd命令行工具
在windows下进行python开发,需要经常使用cmd命令行工具.打开命令行工具有很多种方法,最简单的就是win键+R键弹出运行窗口,然后输入cmd, 就会打开下面这样的窗口. 不同版本,可能配色 ...