关于flex 请看这里  https://css-tricks.com/snippets/css/a-guide-to-flexbox/

太详细啦!!!  还通俗易懂!!! 没啥好说的

不过上面那篇文章中没有仔细说 flex-grow  flex-shrink  flex-basis  是什么含义  请移步这里 http://zhoon.github.io/css3/2014/08/23/flex.html

PS  display:box 和 display:flex-box 是display:flex 的旧版本

PS还可以参考 https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Flexible_boxes

我的例子

<!DOCTYPE html>
<html lang="en">
<head>
<meta name="description" content="[flex]">
</head>
<body>
<div class="flex flex5">
<div class="item">111</div>
<div class="item">222</div>
<div class="item">333</div>
<div class="item">444</div>
</div>
<p>Flexbox nuovo</p>
<div class="flex flex1">
<div>uno</div>
<div>due</div>
<div>tre</div>
</div>
<p>flex一行三列 按比例分配</p>
<p>flex-grow 是横向比例权重</p>
<p>默认 父元素是flex 其子元素是按照一行排列</p>
<div class="flex flex2">
<div class="item">111</div>
<div class="item">222</div>
<div class="item">333</div>
</div>
<h1>flex的居中</h1>
<p>justify-content 是控制水平方向上的位置</p>
<p>align-items是控制垂直方向上的位置</p>
<p>PS 这里每一个item都设置宽度为50% 但是实际上他们还是在一行中 原因见下面</p>
<div class="flex flex3">
<div class="item">111</div>
<div class="item">222</div>
<div class="item">333</div>
</div>
<p>关于flex-wrap</p>
<p>有些时候我们希望同一级别的子元素根据情况来决定是占满一行还是另起一行</p>
<p>默认情况下(指容器是flex的时候) 所有的item都会默认挤在一行内 所以设置宽度不起作用</p>
<p>这时候就需要wrap 值为wrap的时候会另起一行</p>
<div class="flex flex4">
<div class="item">111</div>
<div class="item">222</div>
<div class="item">333</div>
</div>
<p>设置flex direction: row后宽度失效</p>
<p>尽管flex direction默认是row 但是不显示的设置的话可以设置item的宽度</p>
<div class="flex flex42">
<div class="item">111</div>
<div class="item">222</div>
<div class="item">333</div>
</div> <h1>一个响应式NAV</h1>
<div class="flex flex5">
<div class="item">111</div>
<div class="item">222</div>
<div class="item">333</div>
<div class="item">444</div>
</div> <h1>Example1</h1>
<div class="wrapper">
<header class="header">Header</header>
<article class="main">
<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>
</article>
<aside class="aside aside-1">Aside 1</aside>
<aside class="aside aside-2">Aside 2</aside>
<footer class="footer">Footer</footer>
</div> </body>
</html>

CSS

   .flex
{
/* basic styling */
border: 1px solid #555;
font: 14px Arial; /* flexbox setup */
display: -webkit-flex;
display: flex;
}
.flex1{
width: 350px;
height: 200px;
flex-direction: row;
-webkit-flex-direction: row;
}
.flex1 > div
{
-webkit-flex: 1 1 auto;
flex: 1 1 auto; width: 30px; /* To make the transition work nicely. (Transitions to/from
"width:auto" are buggy in Gecko and Webkit, at least.
See http://bugzil.la/731886 for more info.) */ -webkit-transition: width 0.7s ease-out;
transition: width 0.7s ease-out;
} /* colors */
.flex1 > div:nth-child(1){ background : #009246; }
.flex1 > div:nth-child(2){ background : #F1F2F1; }
.flex1 > div:nth-child(3){ background : #CE2B37; } .flex1 > div:hover
{
width: 200px;
} /*ME *********************************************/
.item{
flex-grow:;
height: 200px;
}
.item:nth-child(1){background: pink;}
.item:nth-child(2){background: #33ccdd;}
.item:nth-child(3){background: #ccddcc;} .flex2 .item:nth-child(3){
flex-grow:;
} .flex3{
justify-content: center;
align-items: center;
}
.flex3 .item{
width: 50%;
margin: 0 10px;
} .flex4{
flex-wrap: wrap; /*这个可以使width生效*/
}
.flex4 .item:nth-child(1){
width: 100%;
}
/*PS 不过我们一般不这么写*/ .flex42 {
flex-direction: row;
flex-wrap:wrap;
}
.flex42 .item{
flex-basis:100%;
/*或者*/
flex: 1 0 100%;
}
/* Nav ****************************************/
.flex5{
flex-wrap: wrap;
justify-content: flex-end;
} .flex5 .item{
height: 50px;
width: 70px;
flex-grow:;
} .flex5 .item:nth-child(4){
background:#11eeff;
} @media all and (max-width: 300px) {
.flex5 .item{
width: 100%;
}
} /*Example1 *****************************************/
.wrapper {
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex; -webkit-flex-flow: row wrap;
flex-flow: row wrap; font-weight: bold;
text-align: center;
} .wrapper > * {
padding: 10px;
flex: 1 100%;
} .header {
background: tomato;
} .footer {
background: lightgreen;
} .main {
text-align: left;
background: deepskyblue;
} .aside-1 {
background: gold;
} .aside-2 {
background: hotpink;
} @media all and (min-width: 300px) {
.aside { flex: 1 auto; }
} @media all and (min-width: 500px) {
.main { flex:; }
.aside-1 { order:; }
.main { order:; }
.aside-2 { order:; }
.footer { order:; }
}

CSS Flex的更多相关文章

  1. 【css flex】将多个<div>放在同一行

    使用style里的flex属性 默认情况下,一个div独占一行 使用css选择器给外层div加上以下flex属性,则该div的子div可以在同一行中显示, .runs-paginator-flex-c ...

  2. css flex兼容性

    我测试了一下css flex的兼容性 已经可以兼容到IE10了呀 为啥MDN上面的IE兼容性还是兼容到IE11 有点更新不及时的感觉

  3. 87.CSS Flex 弹性盒模型布局教程(共用的css在48篇文章gird)

    CSS Flex 弹性盒模型布局教程 Flex 是 Flexible Box 的缩写,意为"弹性布局",用来为盒状模型提供最大的灵活性. flex布局就是给任何一个容器添加 dis ...

  4. 【转载】CSS flex属性深入理解

    文章转载自 张鑫旭-鑫空间-鑫生活 http://www.zhangxinxu.com/ 原文链接:https://www.zhangxinxu.com/wordpress/2019/12/css-f ...

  5. CSS flex waterfall layout

    CSS flex waterfall layout https://github.com/YoneChen/waterfall-flexbox https://css-tricks.com/snipp ...

  6. CSS Flex布局完全指南 #flight.Archives002

    Title/CSS Flex布局完全指南 #flight.Archives002 序(from Ruanyf) : 网页布局(layout)是 CSS 的一个重点应用. 布局的传统解决方案,基于盒状模 ...

  7. css flex布局

    关于flex布局的一些简单用法 效果(下图) 实现代码: <!--html--> <div class="wrap"> <div class=&quo ...

  8. css flex方法标题左右两边平衡线

    <html> <div class="title"> <div class="line"></div> < ...

  9. css flex 兼容ios android--商品展示 添加购物车

    https://blog.csdn.net/u010035608/article/details/52711248 <!DOCTYPE html> <html> <hea ...

随机推荐

  1. RabbitMQ安装后启动出错:- unable to connect to epmd on blockstorage: timeout (timed out)

    具体出错信息如下: [root@blockstorage ~]# rabbitmqctl change_password guest RABBIT_PASS Changing password for ...

  2. C#时间日期操作

     一.C# 日期格式 DateTime dt = DateTime.Now; dt.ToString();//2005-11-5 13:21:25 dt.ToFileTime().ToString() ...

  3. SQL Server 执行计划重编译的两大情况

    1.与正确性相关的重编译 1.为表或视图添加列,删除列. 2.为表添加约束.默认值.规则,删除约束.默认值.规则. 3.为表或视图添加索引. 4.如果计划用不用索引而这个索引被删除. 5.删除表中的统 ...

  4. GDAL python教程(1)——用OGR读写矢量数据

    本教程的讲义和源码都是取自Utah State University的openGIS课程 相关资料,包括讲义.源码.数据样例,请从此处下载http://www.gis.usu.edu/~chrisg/ ...

  5. 折腾slidingmenu

    转自自己jekyll博客 alanslab.cn 第一次用gimp做这么大工程,出乎意料,蛮好用的.以前ps倒是蛮熟练的,只摸 过两下gimp,感觉望而生畏.今天硬着头皮折腾了一阵子,发现最起码上图可 ...

  6. tomcat oracle 连接池配置

    <?xml version='1.0' encoding='utf-8'?> <Context displayName="zcgl" docBase=" ...

  7. 使用hibernate 分表做增删改查

    公司项目有一张表的数据量特别大.而且时间越长累积的数据量就越大. 后来DBA决定分表来解决性能问题. 分表是指   一个母体表  一群子表(结构和字段与母体表完全一样) 我们程序对母表操作其实就是对子 ...

  8. SQL Server 2008 批量插入数据时报错

    前几天在SQL Server 2008同步产品数据时,总是提示二进制文本被截断的错误,但是经过检查发现数据都符合格式要求. 百思不得其解,单独插入一条条数据则可以插入,但是批量导入则报错. 批量导入代 ...

  9. js 事件之 createEvent、dispatchEvent

    //document上绑定自定义事件ondataavailable document.addEventListener('customevent', function(event) { alert(e ...

  10. JS实现快排

    /*采用快排的方法排序,取第一个值为轴对数组进行分割排序,不断迭代后实现数组的排序*/ //定义分割函数 function partF(A,low, high){ var temp = A[low]; ...