CSS弹性盒模型flex在布局中的应用
前面的话
前面已经详细介绍过flex弹性盒模型的基本语法和兼容写法,本文将介绍flex在布局中的应用
元素居中
【1】伸缩容器上使用主轴对齐justify-content和侧轴对齐align-items
<style>
.parent{
display: flex;
justify-content: center;
align-items: center;
}
</style>
<div class="parent" style="background-color: lightgrey; height: 100px; width: 200px;">
<div class="in" style="background-color: lightblue;">DEMO</div>
</div>
【2】在伸缩项目上使用margin:auto
<style>
.parent{
display: flex;
}
.in{
margin: auto;
}
</style>
<div class="parent" style="background-color: lightgrey;height: 100px;width: 200px;">
<div class="in" style="background-color: lightblue;">DEMO</div>
</div>
两端对齐
<style>
.parent{
display: flex;
justify-content:space-between
}
</style>
<div class="parent" style="background-color: lightgrey;height: 100px;width: 200px;">
<div class="in" style="background-color: lightblue;">DEMO</div>
<div class="in" style="background-color: lightgreen;">DEMO</div>
<div class="in" style="background-color: lightcyan;">DEMO</div>
<div class="in" style="background-color: lightseagreen;">DEMO</div>
</div>
底端对齐
<style>
.parent{
display: flex;
align-items: flex-end;
}
</style>
<div class="parent" style="background-color: lightgrey;height: 100px;width: 200px;">
<div class="in" style="background-color: lightblue; height:20px;">DEMO</div>
<div class="in" style="background-color: lightgreen; height:30px;">DEMO</div>
<div class="in" style="background-color: lightcyan; height:40px;">DEMO</div>
<div class="in" style="background-color: lightseagreen; height:50px;">DEMO</div>
</div>
输入框按钮
<style>
.inputBox{
display: flex;
width: 250px;
}
.inputBox-ipt{
flex: 1;
}
</style>
<div class="inputBox">
<input class="inputBox-ipt">
<button class="inputBox-btn">按钮</button>
</div>
等分布局
<style>
body,p{margin: 0;}
.parent{
display: flex;
}
.child{
flex:1;
height: 100px;
}
.child + .child{
margin-left: 20px;
}
</style>
<div class="parent" style="background-color: lightgrey;">
<div class="child" style="background-color: lightblue;">1</div>
<div class="child" style="background-color: lightgreen;">2</div>
<div class="child" style="background-color: lightsalmon;">3</div>
<div class="child" style="background-color: pink;">4</div>
</div>
多列自适应布局
<style>
p{margin: 0;}
.parent{display: flex;}
.left,.center{margin-right: 20px;}
.right{flex: 1;}
</style>
<div class="parent" style="background-color: lightgrey;">
<div class="left" style="background-color: lightblue;">
<p>left</p>
<p>left</p>
</div>
<div class="center" style="background-color: pink;">
<p>center</p>
<p>center</p>
</div>
<div class="right" style="background-color: lightgreen;">
<p>right</p>
<p>right</p>
</div>
</div>
悬挂布局
<style>
.box{
display: flex;
background-color: lightgrey;
width: 300px;
}
.left{
margin-right: 20px;
background-color: lightblue;
height: 30px;
}
.main{
flex:1;
}
</style>
<div class="box">
<div class="left">左侧悬挂</div>
<div class="main">主要内容主要内容主要内容主要内容主要内容主要内容主要内容主要内容主要内容主要内容主要内容主要内容主要内容</div>
</div>
全屏布局
<style>
body,p{margin: 0;}
body,html,.parent{height: 100%;}
.parent{
display: flex;
flex-direction: column;
}
.top,.bottom{
height: 50px;
}
.middle{
display: flex;
flex: 1;
}
.left{
width: 100px;
margin-right: 20px;
}
.right{
flex: 1;
overflow: auto;
}
.right-in{
height: 1000px;
}
</style>
<div class="parent" id="parent" style="background-color: lightgrey;">
<div class="top" style="background-color: lightblue;">
<p>top</p>
</div>
<div class="middle" style="background-color: pink;">
<div class="left" style="background-color: orange;">
<p>left</p>
</div>
<div class="right" style="background-color: lightsalmon;">
<div class="right-in">
<p>right</p>
</div>
</div>
</div>
<div class="bottom" style="background-color: lightgreen;">
<p>bottom</p>
</div>
</div>
CSS弹性盒模型flex在布局中的应用的更多相关文章
- 深入理解CSS弹性盒模型flex
× 目录 [1]版本更迭 [2]display [3]基本概念[4]伸缩容器[5]伸缩项目 前面的话 CSS3引入了一种新的布局模型——flex布局.flex是flexible box的缩写,一般称之 ...
- CSS弹性盒模型(flex box)
本文介绍的是 CSS3 规范中引入的新布局模型:弹性盒模型(flex box).随着响应式用户界面的流行,Web 应用一般都要求适配不同的设备尺寸和浏览器分辨率. 浏览器支持: 弹性盒布局的容器(fl ...
- CSS弹性盒模型flex概念
盒模型分为:标准w3c盒模型.IE盒模型.以及css中的伸缩盒模型. 先说CSS的伸缩盒模型:flex模型是CSS3引入的新的布局模型,是flexible box的缩写,一般称之为弹性盒模型.和CSS ...
- css 弹性盒模型Flex 布局
参考文章:http://www.runoob.com/w3cnote/flex-grammar.html Flex 布局是什么:采用Flex布局的元素,称为Flex容器(flex container) ...
- 弹性盒模型 flex box
弹性盒子模型 布局方案 传统的布局方案大多采用div+css+float+position+display来实现,但是随着css3中弹性盒子模型的推出,在前端布局方案中就又多出了一项彪悍的选项. 而因 ...
- css3弹性盒模型flex快速入门与上手(align-content与align-items)
接着上文css3弹性盒模型flex快速入门与上手1继续,上文还剩下两个父容器的属性align-items和align-content. 一.align-content:多行的副轴对齐方式 含义 多行的 ...
- CSS——弹性盒模型
弹性盒子是 CSS3 的一种新的布局模式. CSS3 弹性盒( Flexible Box 或 flexbox),是一种当页面需要适应不同的屏幕大小以及设备类型时确保元素拥有恰当的行为的布局方式. 这东 ...
- 前端设计的常用属性,CSS的盒模型,页面布局的利器
在CSS和HTML结合布局页面的过程中,有一组被人们称为“盒属性”的CSS样式,被广泛的使用到.相信经常布局写页面的朋友们对盒属性一定不陌生.在CSS技术的发展过程中,盒属性也有了许多次改进,今天小编 ...
- css3之弹性盒模型(Flex Box)
CSS3 弹性盒子(Flex Box) 弹性盒子是 CSS3 的一种新的布局模式. CSS3 弹性盒( Flexible Box 或 flexbox),是一种当页面需要适应不同的屏幕大小以及设备类型时 ...
随机推荐
- SQL导入Excel文件
如果表已存在,SQL语句为: insert into aa select * from OPENDATASOURCE('Microsoft.Jet.OLEDB.4.0', 'Data Source=D ...
- No operation was found with the name {http://impl.service.xq.com/}sayHi
org.apache.cxf.common.i18n.UncheckedException: No operation was found with the name {http://impl.ser ...
- SQL 常用语句
替换表中某个字段中的某些字符:(将ConfigValue列中的A值替换为B) update SysConfigParams set ConfigValue=replace(ConfigValue,'A ...
- Eclipse下Tomcat设置
1,Eclipse建立Tomcat服务 1.1 新建Server 首先这里是指,jee版的Eclipse.Eclipse是没有像MyEclipse那样集成Tomcat的,需要我们自己设置. New - ...
- MongoDB与内存
来自 http://www.ttlsa.com/mongodb/mongodb-and-memory/# 但凡初次接触MongoDB的人,无不惊讶于它对内存的贪得无厌,至于个中缘由,我先讲讲Linu ...
- 消息智能路由组件SmartRoute
消息传递在软件开发过程中是一件很常见的事情,而在不同的场景所使用消息传递方式也有所不同,在对象之间制定相关接口方法和对象结构,对于进程之间可能使用内存共享或一些通讯产品,在不同服务器之的消息通讯则使用 ...
- [后端人员耍前端系列]Bootstrap篇:30分钟快速掌握Bootstrap
一.引言 很久没有写过博客了,但是最近这段时间都没有闲着,接触了很多方面.比如一些前端框架和组件.还有移动开发React-Native.以及对.NET框架设计的一些重新认识.这些内容在接下来的时间都会 ...
- 关于使用ABP框架搭建的项目升级时需要注意的问题汇总
ABP理论学习总目录 一步一步使用ABP框架搭建正式项目系列教程 ABP之Module-Zero学习目录 本篇目录 说明 升级方法 问题_01:Log4Net导致编译不成功 2015/12/18更新 ...
- 用JQ仿造礼德财富网的图片查看器
现在就职于一家P2P平台,自然也会关注同行其它网站的前端技术,今天要仿造的是礼德内页的一个图片查看器效果.不过说白了,无论人人贷也好礼德财富也好,很多地方的前端都做的不尽如人意,比如忽略细节.缺乏交互 ...
- android知识杂记(一)
记录项目中用的零碎知识点,用以备忘. android:screenOrientation:portrait 限制横屏 activity启动状态 singleTop 只执行一次,通常用在欢迎页面 sin ...