用Flex实现常见的几种布局
用Flex实现常见的几种布局
1.水平,垂直居中。

<style type="text/css">
.container{
display: flex;
width: 300px;
height: 300px;
border: 1px solid red;
align-items: center; /* 垂直居中*/
justify-content: center; /* 水平居中*/
}
.item{
width: 60px;
height: 60px;
border: 1px solid black;
text-align: center;
background: blue;
}
</style> <div class="container">
<div class="item item1"></div>
</div>
2. 左边固定宽度,右边占满宽度

<style type="text/css">
.container{
display: flex;
width: %;
height: 300px;
border: 1px solid red;
}
.item1{
width: 100px;
background: blue;
}
.item2{
flex: ;
}
</style> <div class="container">
<div class="item item1"></div>
<div class="item item2"></div>
</div>
3.顶部固定高度,下部占满剩余高度

<style type="text/css">
.container{
display: flex;
width: %;
height: 300px;
border: 1px solid red;
flex-direction: column;
}
.item1{
width: %;
height: 20px;
background: blue;
}
.item2{
width: %;
flex: ;
background: #F44336;
}
</style> <div class="container">
<div class="item item1"></div>
<div class="item item2"></div>
</div>
4.顶部,底部固定高度,中间占满剩余高度

<style type="text/css">
.container{
display: flex;
width: %;
height: 300px;
border: 1px solid red;
flex-direction: column;
}
.item1{
width: %;
height: 20px;
background: blue;
}
.item2{
width: %;
flex: ;
background: #F44336;
}
.item3{
width: %;
height: 20px;
background: blue;
}
</style> <div class="container">
<div class="item item1"></div>
<div class="item item2"></div>
<div class="item item3"></div>
</div>
5.中部占满剩余高度,此元素内部采用"左边固定宽度,右边占满剩余宽度"

<style type="text/css">
.container{
display: flex;
width: %;
height: 600px;
border: 1px solid red;
flex-direction: column;
}
.header{
height: 100px;
width: %;
background: #3be662;
}
.body{
flex: ;
width: %;
background: red;
display: flex;
flex-direction: row;
}
.footer{
width: %;
height: 100px;
background: blue;
}
.left{
width: 100px;
background: #d7b052;
}
.right{
flex: ;
background: #b1c2bd;
} </style> <div class="container">
<div class="header"></div>
<div class="body">
<div class="left"></div>
<div class="right"></div>
</div>
<div class="footer"></div>
</div>
Flex兼容性写法
1.盒子的兼容性写法:
.box{
display: -webkit-flex; /* 新版本语法: Chrome 21+ */
display: flex; /* 新版本语法: Opera 12.1, Firefox 22+ */
display: -webkit-box; /* 老版本语法: Safari, iOS, Android browser, older WebKit browsers. */
display: -moz-box; /* 老版本语法: Firefox (buggy) */
display: -ms-flexbox; /* 混合版本语法: IE 10 */
}
2.子元素的兼容性写法:
.flex1 {
-webkit-flex: ; /* Chrome */
-ms-flex: /* IE 10 */
flex: ; /* Spec - Opera 12.1, Firefox 20+ */
-webkit-box-flex: /* 老版本语法 - iOS 6-, Safari 3.1-6 */
-moz-box-flex: ; /* 老版本语法 - Firefox 19- */
}
最后附上各个浏览器对Flex的支持程度:

用Flex实现常见的几种布局的更多相关文章
- HTML的三种布局:DIV+CSS、FLEX、GRID
Div+css布局 也就是盒子模型,有W3C盒子模型,IE盒子模型.盒子模型由四部分组成margin.border.padding.content. 怎么区别这两种模型呢,区别在于w3c中的width ...
- Android开发之基本控件和详解四种布局方式
Android中的控件的使用方式和iOS中控件的使用方式基本相同,都是事件驱动.给控件添加事件也有接口回调和委托代理的方式.今天这篇博客就总结一下Android中常用的基本控件以及布局方式.说到布局方 ...
- 常见div+css网页布局(float,absolute)
网页布局-常见 1, float布局 (1)常规方法 <div id="warp"> <div id="column&quo ...
- 【转】Android UI 五种布局
在一个Android应用中,Layout是开发中的一个很重要环节,Layout是组成UI不可缺少的一部分. ## Android UI 核心类 在Android应用构建UI的方法有以下几种: 单纯使用 ...
- Extjs--12种布局方式
按照Extjs的4.1的文档来看,extjs的布局方式大致有12种,下面一一介绍,有些代码就是文档中的. 1.Border 边界布局 border布局,最多可以将页面分割为"东南西北中&qu ...
- CSS 常见的8种选择器 和 文本溢出问题
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>c ...
- 精华阅读第 13 期 |常见的八种导致 APP 内存泄漏的问题
本期是移动开发精英俱乐部的第13期文章,都是以技术为主,所以这里就不过多的进行赘述了,我们直接看干货内容吧!本文系ITOM管理平台OneAPM整理. 实际项目中的MVVM(积木)模式–序章 导读:开篇 ...
- Android-基本控件和详解四种布局方式
转自:https://www.cnblogs.com/ludashi/p/4883915.html 一.常用基本控件 1.TextView 看到Android中的TextView, 我不禁的想到了iO ...
- Flex元素布局规则总结,以及布局和容器
一.Flex中的元素分类从功能层面可以把Flex中的元素分为组件(Components)和容器(Containers)两大类:组件 - 是指那类具有明确交互或数据展示功能的元素,例如Button.Ch ...
随机推荐
- UNDO表空间损坏导致数据库无法OPEN
在数据库undo表空间文件损坏.或者undo表空间文件缺失的情况下.无法打开数据库. 这两种情况都能够视为一种情况处理,解决方法一样. 场景:在23:10的时候新建一个undo表空间undotbs02 ...
- solr6.6 索引 word文档
本文是solr6.6 导入 pdf/doc/txt/json/csv/xml文件 的继续,上篇在索引文件,唯独07格式的word文档不能正常抽取数据,进过研究测试终于,记录下属过程. 其它步骤基本和s ...
- Jquery获取当前行的数据
取表格当前行数据js代码: Java代码 $(function() { $(".myclass").each(function(){ var tmp=$(this).chi ...
- vue 表单验证实例
1.注册 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF- ...
- lodash round
_.round(number, [precision=0]) 根据 precision 四舍五入 number. _.round(4.006); // => 4 _.round(4.006, 2 ...
- POJ 2392 Space Elevator(贪心+多重背包)
POJ 2392 Space Elevator(贪心+多重背包) http://poj.org/problem?id=2392 题意: 题意:给定n种积木.每种积木都有一个高度h[i],一个数量num ...
- 在OpenERP报表中使用selection 类型字段
OpenERP 在报表的创作中始终有一个麻烦,那就是在报表中通过对象导航的方式获取的 selection 字段只能获取到该字段的 key 而不能获取对应的用户友好的描述文本. 举个具体的例子:销售单的 ...
- 【Python3 爬虫】07_正则表达式(原子)
原子是正则表达式的最基本的组成单位,而且在每个模式中最少包含一个原子.原子是由所有那些未显示指定为元字符的打印和非打印字符组成. 原子分类 1.普通字符作为原子 普通字符是编写正则表达式时最常见的原子 ...
- 【BIEE】18_时间序列函数的使用
三个时间序列函数 AGO: 实现同环比 TO DATE:实现累计指标,如MTD月累计.YTD年累计 Period Rolling:当前时间的x个时间单位开始到y个时间单位结束这一时段内的度量总和 BI ...
- 使用jconsole监控tomcat(推荐配置)
1.在tomcat启动过程中,开启相应的参数配置 $Tomcat_home/bin/catalina.sh: 1 2 3 4 -Dcom.sun.management.jmxremote -Dcom. ...