公共样式:

    <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常用布局的更多相关文章

  1. Flex 常用布局

    1.flex布局 1.1  容器指定为flex布局 .box{display: flex;} 1.2 行元素指定flex布局 .box{display:inline-flex} 2.容器的属性 2.1 ...

  2. CSS3动画属性和flex弹性布局各个属性

    [CSS3动画的使用] 1.声明一个关键帧(动画): @keynames name{ from{} to{} } 每个阶段的写法: ①可以直接使用from-to的写法 ②可以设置0%-100%的写法, ...

  3. ExtJs常用布局--layout详解(含实例)

    序言: 笔者用的ExtJs版本:ext-3.2.0 ExtJs常见的布局方式有:border.form.absolute.column.accordion.table.fit.card.anchor ...

  4. Flutter常用布局组件

    Flutter控件本身通常由许多小型.单用途的控件组成,结合起来产生强大的效果,例如,Container是一种常用的控件,由负责布局.绘画.定位和大小调整的几个控件组成,具体来说,Container是 ...

  5. 2021年3月-第02阶段-前端基础-Flex 伸缩布局-移动WEB开发_流式布局

    移动web开发流式布局 1.0 移动端基础 1.1 浏览器现状 PC端常见浏览器:360浏览器.谷歌浏览器.火狐浏览器.QQ浏览器.百度浏览器.搜狗浏览器.IE浏览器. 移动端常见浏览器:UC浏览器, ...

  6. CSS弹性盒模型flex在布局中的应用

    × 目录 [1]元素居中 [2]两端对齐 [3]底端对齐[4]输入框按钮[5]等分布局[6]自适应布局[7]悬挂布局[8]全屏布局 前面的话 前面已经详细介绍过flex弹性盒模型的基本语法和兼容写法, ...

  7. python:页面布局 后台管理页面之常用布局

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...

  8. 常用布局,div竖直居中

    常用两列布局,多列布局和div竖直居中 body { margin:; padding:; } .w200 { width: 200px; } .mar-left200 { margin-left: ...

  9. 跟我学android-android常用布局介绍

    在上一章我们曾经谈到,Android平台的界面 是使用XML的方式设计的,然后在上一章我们只做了一个简单的界面,在这章,我们将介绍如何使用常用的控件设计实用的界面. Android中的视图都是继承Vi ...

随机推荐

  1. OpenAPI 3.0 规范-食用指南

    概述 OpenAPI 3.0 规范由 8 个根对象组成: openapi info servers paths components security tags externalDocs OpenAP ...

  2. Docker 与 K8S学习笔记(二十四)—— 工作负载的使用

    我们前面讲了很多关于Pod的使用,但是在实际应用中,我们不会去直接创建Pod,我们一般通过Kubernetes提供的工作负载(Deployment.DeamonSet.StatefulSet.Job等 ...

  3. sql-删除重复数据-oracle

    删除重复数据 准备重复数据 create table mystudent ( stuno number , stuname varchar2(20), stuage number ); insert ...

  4. python小题目练习(三)

    题目:输出1!+2!+3!+--+10!的结果代码实现: # 定义一个函数来递归实现阶乘操作def cycle(num): if num == 1: return 1 else: return num ...

  5. httrack使用cookie克隆站点

    关于cookies使用在这里官方已有说明,意思是将cookies.txt文件放在项目的根目下即可,格式也给了说明.问题是cookie值太多,手动不好整理,所以就需要用到神器editthiscookie ...

  6. SSH隧道代理

    应用场景: A机器可以通过SSH连接到B机器,然后A想用B的身份访问B所在的资源(主要用于浏览器访问) 命令: A机器通过ssh与B建立连接,并暴露3128端口:ssh -N -D 127.0.0.1 ...

  7. ICMP 介绍

    简介 ICMP(Internet 控制报文协议,Internet Control Message Protocol , RFC 792).主要用于在IP主机与路由器之间传递控制消息,用于报告主机是否可 ...

  8. 4-12 Spring Security + JWT

    Spring Security + JWT 此前,在处理登录的业务中,当视为登录成功时,返回的字符串并不是JWT数据,则应该将此数据改为必要的JWT数据. @Service public class ...

  9. Kafka Topic Partition Offset 这一长串都是啥?

    摘要:Offset 偏移量,是针对于单个partition存在的概念. 本文分享自华为云社区<Kafka Topic Partition Offset 这一长串都是啥?>,作者: gent ...

  10. 第三天python3 字典

    字典 dict 特点:key-value键值对的数据的集合    可变的.无序的.key不重复:非线性结构: 字典的初始化 d=dict() 或者 d = { } dict(**kwargs) 使用n ...