CSS弹性盒布局(display:flex)
CSS弹性布局(display:flex)
参考:
http://www.runoob.com/w3cnote/flex-grammar.html
https://www.jianshu.com/p/5856c4ae91f2
http://www.ruanyifeng.com/blog/2015/07/flex-grammar.html
https://www.cnblogs.com/xuyuntao/articles/6391728.html
主要内容:
父级:
display:flex; (兼容绝大部分浏览器):-webkit- 真实工作下使用postCss插件-自动添加浏览器兼容
display: -webkit-flex; /* Safari */
display: flex;
*如果使用了弹性布局,子元素不需要使用浮动float 父级身上的常用属性:
justify-content: 子元素水平排列
flex-start(默认) 从左开始
flex-end 从右开始
center 居中!!
space-between 两端对齐
space-around 子元素张开手分布 align-items 子元素垂直排列
flex-start(默认) 从上开始
flex-end 从下开始
center 居中!!
stretch(默认值):如果项目未设置高度或设为auto,将占满整个容器的高度
baseline: 项目的第一行文字的基线对齐 align-content 多行子元素垂直排列
flex-start: 与交叉轴的起点对齐。
flex-end: 与交叉轴的终点对齐。
center: 与交叉轴的中点对齐。
space-between: 与交叉轴两端对齐,轴线之间的间隔平均分布。
space-around: 每根轴线两侧的间隔都相等。所以,轴线之间的间隔比轴线与边框的间隔大一倍。
stretch(默认值): 轴线占满整个交叉轴。 flex-flow(基本不用,面试可能会提到)
flex-flow属性是flex-direction属性和flex-wrap属性的简写形式,默认值为row nowrap
flex-flow: <flex-direction> <flex-wrap>;
举例:flex-flow:column wrap; flex-direction 子元素排列方向
row(默认值):主轴为水平方向,起点在左端。
row-reverse:主轴为水平方向,起点在右端。
column:主轴为垂直方向,起点在上沿。
column-reverse:主轴为垂直方向,起点在下沿。 flex-wrap 子元素一行排不下如何换行
nowrap(默认):不换行
wrap:换行,第一行在上方
wrap-reverse:换行,第一行在下方 子集身上的属性:
flex 是flex-grow, flex-shrink 和 flex-basis的简写,默认值为0 1 auto。后两个属性可选
将行分为定义比例的几份
*子元素在划分父元素宽度,先刨除固定宽度 align-self 允许单个子元素有与其他项目不一样的垂直对齐方式,可覆盖align-items属性
.item {
align-self: auto | flex-start | flex-end | center | baseline | stretch;
} flex-grow 定义子元素的放大比例,默认为0,即如果存在剩余空间,也不放大
.item {
flex-grow: <number>; /* default 0 */ <number>只代表缩放系数
} order 定义子元素的排列顺序。数值越小,排列越靠前,默认为0
.item {
order: <integer>;
}
练习案例:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>flex布局案例-淘宝底部导航栏</title>
<link rel="stylesheet" href="bootstrap/css/bootstrap.css">
<style>
* {
margin: 0;
padding: 0;
list-style: none;
}
.footer-nav{
width: 100%;
height: 60px;
background-color: grey;
display: flex;
position: absolute;
left: 0;
bottom: 0;
}
.footer-nav .tab{
width: 20%;
box-sizing: border-box;
border-left: 1px solid red;
flex: 1;
text-align: center;
line-height: 30px;
font-size: 16px;
color: white;
}
.footer-nav .tab .tab-icon{
height: 30%;
}
</style>
</head>
<body>
<div class="footer-box">
<div class="footer-nav">
<span class="tab">
<span class="tab-icon glyphicon glyphicon-home"></span>
<p class="text">首页</p>
</span>
<span class="tab">
<span class="tab-icon glyphicon glyphicon-shopping-cart"></span>
<p class="text">购物车</p>
</span>
<span class="tab">
<span class="tab-icon glyphicon glyphicon-list-alt"></span>
<p class="text">订单列表</p>
</span>
<span class="tab">
<span class="tab-icon glyphicon glyphicon-user"></span>
<p class="text">我的淘宝</p>
</span>
<span class="tab">
<span class="tab-icon glyphicon glyphicon-option-horizontal"></span>
<p class="text">更多</p>
</span>
<span class="tab">
<span class="tab-icon glyphicon glyphicon-grain"></span>
<p class="text">欢度清明</p>
</span>
</div>
</div>
</body>
</html>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="style/flex-1.css">
</head>
<body>
<div class="outer">
<div class="item div1">1</div>
<div class="item div2">2</div>
<div class="item div3">3</div>
<div class="item div4">4</div>
<div class="item">5</div>
<div class="item">6</div>
<div class="item">7</div>
</div>
</body>
</html>
HTML代码
*{
margin:;
padding:;
list-style: none;
}
.outer{
width: 500px;
height: 500px;
border: 1px solid red;
margin: 30px auto;
display: flex;
flex-wrap: wrap;
align-content:flex-start;
}
.item{
width: 125px;
border: 1px solid #ff1bbe;
background-color: #0D47A1;
height: 125px;
box-sizing: border-box;
font-size: 32px;
color: white;
line-height: 125px;
text-align: center;
align-content: flex-start;
}
css代码

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
* {
margin: 0;
padding: 0;
list-style: none;
}
.outer {
width: 500px;
height: 500px;
border: 1px solid red;
margin: 30px auto;
display: flex;
flex-wrap: wrap;
align-content: flex-start;
}
.item {
border: 1px solid #ff1bbe;
background-color: #0D47A1;
height: 125px;
box-sizing: border-box;
font-size: 32px;
color: white;
line-height: 125px;
text-align: center;
}
.div1{width: 80px}
.div2{flex: 1}
.div3{flex: 2}
</style>
</head>
<body>
<div class="outer">
<div class="item div1">1</div>
<div class="item div2">2</div>
<div class="item div3">3</div> </div>
</body>
</html>


<!DOCTYPE=html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<title>
关于文档元素测试
</title>
<style> #father{ width:200px;
display:flex;
flex-direction:row;
flex-wrap:wrap;
align-content:center;
height:200px;
background-color:grey;
}
.son1{ height:30px;
width:100px;
background-color:orange;
} .son2{ height:30px;
width:100px;
background-color:red;
} .son3{
height:30px;
width:100px;
background-color:#08a9b5;
} .son4{
height:30px;
width:100px;
background-color:#9ad1c3;
} .son5{ height:30px;
width:100px;
background-color:rgb(21,123,126);
}
</style>
</head>
<body> <div id="father">
<div class="son1">q</div>
<div class="son2">w</div>
<div class="son3">e</div>
<div class="son4">e</div>
<div class="son5">e</div>
</div> </body>
</html>
flex布局换行空白间隙之align-content
参考:https://blog.csdn.net/txfyteen/article/details/82663029
CSS弹性盒布局(display:flex)的更多相关文章
- 弹性盒布局display:flex详解
一:弹性盒子 随着响应式设计的流行,网站开发者在设计网页布局时往往要考虑到页面在适配不同分辨率的浏览器时其内部组件位置大小都会产生变化,因此需要设计者根据窗口尺寸来调整布局,从而改变组件的尺寸和位置, ...
- 弹性盒模型display:flex
Flex布局意为"弹性布局",用来为盒模型提供更多灵活性.此外,Flex定义的容器可以对块级元素(display: flex;)或行内元素(display: inline-flex ...
- 弹性盒布局(flex)
一.Flex 布局是什么? Flex 是 Flexible Box 的缩写,意为"弹性布局",用来为盒状模型提供最大的灵活性. 任何一个容器都可以指定为 Flex 布局. .box ...
- CSS弹性盒布局
<html> <head> <meta charset="utf-8"/> <title></title> <st ...
- 弹性盒布局详解(display: flex;)
弹性盒布局详解 弹性盒介绍 弹性盒的CSS属性 开启弹性盒 弹性容器的CSS属性 flex-direction设置弹性元素在弹性容器中的排列方向 主轴与侧轴(副轴) flex-wrap设置弹性容器空间 ...
- css怪异盒模型和弹性盒布局(flex)详解及其案例
一.怪异盒模型 怪异盒模型的属性是box-sizing,他有两个属性值: 1.content-box 这是由 CSS2.1 规定的宽度高度行为.宽度和高度分别应用到元素的内容框.在宽度和高度之外绘制元 ...
- css笔记 - flex弹性盒布局
flex: display:-webkit-box | -moz-box;盒布局 -webkit-box-flex | -moz-box-flex;弹性盒布局 -webkit-box-ordinal- ...
- CSS弹性盒模型(flex box)
本文介绍的是 CSS3 规范中引入的新布局模型:弹性盒模型(flex box).随着响应式用户界面的流行,Web 应用一般都要求适配不同的设备尺寸和浏览器分辨率. 浏览器支持: 弹性盒布局的容器(fl ...
- 弹性盒模型,flex布局
弹性盒模型 弹性盒子是css3的一种新布局模式,由容器(父元素)和项目(子元素)组成. 弹性盒子是一种当页面需要适应不同的屏幕大小以及设备类型时确保元素拥有恰当的行为的布局方式. 引入弹性盒模型的 ...
随机推荐
- Install Redis 3.2 on Ubuntu
Install Redis 3.2 on Ubuntu It’s very easy to install Redis 3 on Ubuntu 16, just need to add PPA rep ...
- [转]list的交集,差集,并集
原文地址:https://www.cnblogs.com/changfanchangle/p/8966860.html 工作中用到了list的取差集,发现还是挺好用的.所以记录下. 需求 list的方 ...
- C#时间格式化显示AM/PM
.ToString("MM/dd/yyyy hh:mm:ss:ffff tt")); //12小时制 .ToString("MM/dd/yyyy HH:mm:ss:fff ...
- 【ML入门系列】(一)训练集、测试集和验证集
训练集.验证集和测试集这三个名词在机器学习领域极其常见,但很多人并不是特别清楚,尤其是后两个经常被人混用. 在有监督(supervise)的机器学习中,数据集常被分成2~3个,即:训练集(train ...
- 关于QQ邮箱有时候接受不到邮件的解决
1.很可能是被当作垃圾邮件拦截了,这时候就要自己找回 2.首先点击邮箱首页 3.在最后一行倒数第三个选择自助查询 4.一般在收信查询或者删信查询里面,找到被删的邮件,添加到白名单就好了
- Android手机用wifi连接adb调试的方法
https://www.jianshu.com/p/dc6898380e38 0x0 前言 Android开发肯定要连接pc的adb进行调试,传统的方法是用usb与pc进行连接,操作简单即插即用,缺点 ...
- SpringBoot面试题及答案整理
1. Spring 和 SpringBoot 有什么不同? Spring 框架提供多种特性使得 web 应用开发变得更简便,包括依赖注入.数据绑定.切面编程.数据存取等等. 随着时间推移,Spring ...
- Ubuntu下pdf和图片互转
前边文章可以将ppt转换为pdf 查看 使用unoconv将ppt转为pdf,再使用imagemagick将pdf转为图片 这次想将pdf和图片进行互转 当前目录下只有2.ppt 1.ppt转pdf ...
- python中导入一个需要传参的模块
最近跑实验,遇到了一个问题:由于实验数据集比较多,每次跑完一个数据集就需要手动更改文件路径,再将文件传到服务器,再运行实验,这样的话效率很低,必须要专门看着这个实验,啥时候跑完就手动修改运行下一个实验 ...
- Flask 学习笔记(1)--环境安装
Flask 官网:http://flask.pocoo.org/ Flask文档:http://docs.jinkan.org/docs/flask/ 0x01 安装方式 安装步骤很简单,就是这个样子 ...