CSS Flex
关于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的更多相关文章
- 【css flex】将多个<div>放在同一行
使用style里的flex属性 默认情况下,一个div独占一行 使用css选择器给外层div加上以下flex属性,则该div的子div可以在同一行中显示, .runs-paginator-flex-c ...
- css flex兼容性
我测试了一下css flex的兼容性 已经可以兼容到IE10了呀 为啥MDN上面的IE兼容性还是兼容到IE11 有点更新不及时的感觉
- 87.CSS Flex 弹性盒模型布局教程(共用的css在48篇文章gird)
CSS Flex 弹性盒模型布局教程 Flex 是 Flexible Box 的缩写,意为"弹性布局",用来为盒状模型提供最大的灵活性. flex布局就是给任何一个容器添加 dis ...
- 【转载】CSS flex属性深入理解
文章转载自 张鑫旭-鑫空间-鑫生活 http://www.zhangxinxu.com/ 原文链接:https://www.zhangxinxu.com/wordpress/2019/12/css-f ...
- CSS flex waterfall layout
CSS flex waterfall layout https://github.com/YoneChen/waterfall-flexbox https://css-tricks.com/snipp ...
- CSS Flex布局完全指南 #flight.Archives002
Title/CSS Flex布局完全指南 #flight.Archives002 序(from Ruanyf) : 网页布局(layout)是 CSS 的一个重点应用. 布局的传统解决方案,基于盒状模 ...
- css flex布局
关于flex布局的一些简单用法 效果(下图) 实现代码: <!--html--> <div class="wrap"> <div class=&quo ...
- css flex方法标题左右两边平衡线
<html> <div class="title"> <div class="line"></div> < ...
- css flex 兼容ios android--商品展示 添加购物车
https://blog.csdn.net/u010035608/article/details/52711248 <!DOCTYPE html> <html> <hea ...
随机推荐
- 使用prototype扩展的JavaScript常用函数库
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--> ...
- 20151214--JSTL
- BZOJ 1570: [JSOI2008]Blue Mary的旅行( 二分答案 + 最大流 )
二分答案, 然后对于答案m, 把地点分成m层, 对于边(u, v), 第x层的u -> 第x+1层的v 连边. 然后第x层的u -> 第x+1层的u连边(+oo), S->第一层的1 ...
- Java学习之javassist
1.读取和输出字节码 ClassPool pool = ClassPool.getDefault(); //会从classpath中查询该类 CtClass cc = pool.get("t ...
- jQuery1.9.1针对checkbox的调整
在jquery 1.8.x中的版本,我们对于checkbox的选中与不选中操作如下: 判断是否选中 $('#checkbox').prop('checked') 设置选中与不选中状态: $('#che ...
- Python进阶之闭包
闭包 .note-content {font-family: "Helvetica Neue",Arial,"Hiragino Sans GB","S ...
- You have not agreed to the Xcode license.
You have not agreed to the Xcode license. Before running the installer again please agree to the lic ...
- threadid=1: thread exiting with uncaught exception (group=0x40db8930)
异常信息如下: 07-26 17:23:49.521: W/dalvikvm(29229): threadid=1: thread exiting with uncaught exception (g ...
- Apache新版配置虚拟主机的注意事项
1.关于没有默认索引文件(index.php或者index.html)时,列出目录:需要开启模块 LoadModule autoindex_module modules/mod_autoindex.s ...
- Google Chrome浏览器的使用方法
Google Chrome浏览器 [原文地址:http://www.cnblogs.com/QLeelulu/archive/2011/08/28/2156402.html ] 在Google Chr ...