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 ...
随机推荐
- LayUI+SSM实现一个简单的后台管理系统
该后台管理系统是用于管理视频网站数据的,目前分5个菜单项,这篇博客主要讲述[影片管理]的具体功能和实现 后台代码结构和[影片管理]的界面如下图 该界面分为上下2部分,[搜索条件]和[影片列表],2部分 ...
- centos通过日志查入侵
1. Linux查看/var/log/wtmp文件查看可疑IP登陆 last -f /var/log/wtmp 该日志文件永久记录每个用户登录.注销及系统的启动.停机的事件.因此随着系统正常运行时间的 ...
- GameFramework食用指南
1.框架简介 GF框架分两部分,GameFramework(GF)和UnityGameFramework(UGF): 通过接口的形式对Unity引擎进行了解耦: GF独立于Unity,具体业务逻辑实现 ...
- vscode的安装、切换为中文简体、集成sass
VScode设置中文 打开vscode ,按快捷键"Ctrl+Shift+P" 输入configure language,回车 选择安装其他语言 (默认是英文的) 选择简体中安装( ...
- NIO.2中Path、 Paths、Files类的使用
- java后端接受Vue传递的List
Failed to resolve argument 1 of type 'java.util.List' org.springframework.web.bind.MissingServletReq ...
- 5-2 SpringCloud | 微服务
服务器端项目演进 服务器初期状态 最早的服务器就是安装部署了一些静态页面 功能非常单一,只能做信息的呈现和输出 服务器动态页面 后来因为业务和技术的发展,页面连接了数据库,页面中大部分数据来自于数据库 ...
- Docker详解(上)
Docker 学习 Docker概述 Docker安装 Docker命令 镜像命令 容器命令 操作命令 ... Docker镜像 容器数据卷 DockerFile Docker网络原理 IDEA整合D ...
- 聊聊 C++ 中的几种智能指针 (上)
一:背景 我们知道 C++ 是手工管理内存的分配和释放,对应的操作符就是 new/delete 和 new[] / delete[], 这给了程序员极大的自由度也给了我们极高的门槛,弄不好就得内存泄露 ...
- input函数的高级使用
经典的a+b问题终于重出江湖了 a=input('a = ') b=input('b = ') print(a+b)//error,因为此时ab是字符串类型,其加号起到的是连接的作用 所以这就是类型转 ...