一、伸缩布局的起源

  1、之前我们想要适应不同的浏览器,一般采用的是设置宽度、高度为父级元素的百分比,但是有时候百分比的计算是相当复杂的,加上有时候还有规定的宽度要设置,所以,伸缩布局的出现是我们所急需的。

  例:将一个section三等分,其中放入3个div

<!DOCTYPE html>
<html lang="en"> <head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>伸缩布局</title>
<style>
/* 原始的模式 */
/* section{
width: 1000px;
height: 200px;
}
div{
float:left;
width:33.33%;
height:20px;
background-color: red;;
}
div:nth-child(2){
background-color: blue;
}
div:last-child{
background-color:green;
} */
/* 采用伸缩布局 */
section {
display: flex;
width: 1000px;
} div {
flex: 1;
height: 20px;
background-color: red;
} div:nth-child(2) {
background-color: blue;
} div:last-child {
background-color: green;
}
</style>
</head> <body>
<section>
<div></div>
<div></div>
<div></div>
</section>
</body> </html>

二、伸缩布局的使用

  1、可以添加具体宽度

div:nth-child(2) {
width: 20px;
background-color: blue;
}

  2、可以设置最小宽度,这样当屏幕缩小到小于最小宽度时,就会出现滚动条

  min-width:500px;

  3、伸缩布局的排列方式:主轴、方向

  flex-direction: row;
/* 默认的:横向排列 */
flex-direction: column;
/* 纵向排列 */
flex-direction: row-reverse;
/* 横向逆序 */
flex-direction: column-reverse;
/* 纵向逆序 */

  4、主轴的对齐方式

  

 /* justify-content一行的情况 */
/* 从左到右,默认的顺序 */
/* justify-content: flex-start; */
/* 从右到左的,逆序 */
/* justify-content: flex-end; */
/* 子元素在父元素的中间显示 */
/* justify-content: center; */
/* 均分,贴边 */
/* justify-content: space-around; */
/* 均分,不贴边 */
/* justify-content: space-between; */
/* 纵向逆序 */
/* align-content 多行的情况()
值同,默认是strentch
必须在父元素例配置{display:flex;flex-direction:row;flex-wrap:wrap;}
*/
 

  5、order:控制子元素的裴烈顺序:默认是0,越小的值越排在前面,可以是负数

  6、flex-wrap是否换行:no;默认收缩显示wrap;换行wrap-reverse;以相反的顺序换行

  7、aligin-items侧主轴的对齐方式:stretch;子元素高度拉伸(默认)center;居中felx-start;在开头;flex-end;在底边

  8、flex-flow:排列方向 是否换行的综合接卸形式

最新文章

  1. 19:A*B问题
  2. Angularjs 的 ngInfiniteScroll 的使用方法
  3. 元数据集 DatabaseMetaData ResultSetMetaData
  4. BestCoder Round #73
  5. 原 Linux搭建SVN 服务器
  6. [二分匹配]URAL1721Two Sides of the Same Coin
  7. bzoj2427
  8. HDU2037 贪心 动归均可+证明
  9. 浅析Java源码之ArrayList
  10. iOS-----------关于组件化
  11. shell编程 之 函数
  12. (6)学习笔记 ) ASP.NET CORE微服务 Micro-Service ---- AOP框架
  13. MongoDB C# 驱动的各种版本下载地址
  14. openssl之EVP系列之13---EVP_Open系列函数介绍
  15. Office自动生成目录步骤(非常实用)(图文详解)
  16. hdu1754 I Hate It(线段树单点更新,区间查询)
  17. mysql性能测试--sysbench实践
  18. mysql分表分库选型
  19. python3+pyzbar+Image 进行图片二维码识别
  20. 将Linux代码移植到Windows的简单方法

热门文章

  1. 配置文件一web.xml
  2. H5 回到顶部按钮
  3. pinmap 和 pin allocation
  4. System Verilog的概念以及与verilog的对比
  5. SQL 分组后获取每组中最大值
  6. private变量引用问题
  7. 安装MySql社区版(35-3)
  8. Win10系统无法安装可选功能提示错误代码0x800F081F的解决方法
  9. SQLServer 2008 还原数据库备份版本不兼容的问题
  10. Python全栈开发:装饰器实例