css3伸缩布局属性总结
http://www.css88.com/book/css/properties/flex/flex-basis.htm
http://c7sky.com/dive-into-flexbox.html
http://www.css88.com/archives/5741
http://caibaojian.com/demo/flexbox/align-items.html
http://caibaojian.com/demo/flexbox/align-content.html
一共2个标准一个是dispaly:box ;老的,另一个是dispaly:flex
用在父容器上的值:
div{
display: -webkit-box;
display: -moz-box;
display: -o-box;
display: -ms-flexbox;
display: -webkit-flex;
display: -moz-flex;
display: -ms-flex;
display: -o-flex;
display: flex;
-webkit-flex-wrap:wrap;
flex-direction:wrap;
align-content:flex-start;
-webkit-box-pack:end;-moz-box-pack:end;-ms-box-pack:end;
-webkit-box-align:stretch;-moz-box-align:stretch;-ms-box-align:stretch
-webkit-box-orient:vertical;-moz-box-orient:vertical;-ms-box-orient:vertical
}
align-content 属性在当灵活容器内的各项没有占用交叉轴上所有可用的空间时对齐容器内的各项(垂直)。
提示:使用 justify-content 属性对齐主轴上的各项(水平)。
justify-content:在子元素 不是flex的时候起作用,可以单行
align-content 会更改 flex-wrap 的行为。他只能多行使用,它和 align-items 相似,但是不是对齐伸缩项目,它对齐的是伸缩行。可能你已经想到了,它接受的值也很相似:
当伸缩容器的侧轴还有多余空间时,本属性可以用来调准「伸缩行」在伸缩容器里的对齐方式,这与调准伸缩项目在主轴上对齐方式的 <' justify-content '> 属性类似。请注意本属性在只有一行的伸缩容器上没有效果。
- 对应的脚本特性为alignContent。
用在子容器上的值: box-flex flex-grow flex-shrink flex-basis order
.flex-container {
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-flex-direction: row;
-ms-flex-direction: row;
flex-direction: row;
-webkit-flex-wrap: nowrap;
-ms-flex-wrap: nowrap;
flex-wrap: nowrap;
-webkit-justify-content: flex-start;
-ms-flex-pack: start;
justify-content: flex-start;
-webkit-align-content: flex-end;
-ms-flex-line-pack: end;
align-content: flex-end;
-webkit-align-items: stretch;
-ms-flex-align: stretch;
align-items: stretch;
background: #000;
height:200px;
}
.flex-item{background: #fe6;margin:2px; padding:5px}
.flex-item:nth-child(1) {
-webkit-order: 0;
-ms-flex-order: 0;
order: 0;
-webkit-flex: 1 1 auto;
-ms-flex: 1 1 auto;
flex: 1 1 auto;
-webkit-align-self: auto;
-ms-flex-item-align: auto;
align-self: auto;
}
.flex-item:nth-child(2) {
-webkit-order: 0;
-ms-flex-order: 0;
order: 0;
-webkit-flex: 1 1 auto;
-ms-flex: 1 1 auto;
flex: 1 1 auto;
-webkit-align-self: auto;
-ms-flex-item-align: auto;
align-self: auto;
}
.flex-item:nth-child(3) {
-webkit-order: 0;
-ms-flex-order: 0;
order: 0;
-webkit-flex: 1 1 auto;
-ms-flex: 1 1 auto;
flex: 1 1 auto;
-webkit-align-self: auto;
-ms-flex-item-align: auto;
align-self: auto;
}
.flex-item:nth-child(4) {
-webkit-order: 0;
-ms-flex-order: 0;
order: 0;
-webkit-flex: 0 1 auto;
-ms-flex: 0 1 auto;
flex: 0 1 auto;
-webkit-align-self: auto;
-ms-flex-item-align: auto;
align
Flexbox 规范时间表:
- 2009年7月 工作草案 (display: box;)
- 2011年3月 工作草案 (display: flexbox;)
- 2011年11月 工作草案 (display: flexbox;)
- 2012年3月 工作草案 (display: flexbox;)
- 2012年6月 工作草案 (display: flex;)
- 2012年9月 候选推荐 (display: flex;)
浏览器商为了自救,搞了个私有前缀,因此定义一个伸缩盒特别麻烦:
因此我在定下第2个规范,CSS统一用less来写。less是一种动态的样式表语言,它为CSS增加变量,组合,函数,运算等语法,让CSS更便于编写,复用与维护。 有了less,上面那一坨东西可以封装成一个函数,用不着每次都写这么多让你狂抓的候选值。
.flexbox() {//定义
// 2009 spec
display: -webkit-box;
display: -moz-box;
display: -o-box;
// tweener
display: -ms-flexbox;
// new spec
display: -webkit-flex;
display: -moz-flex;
display: -ms-flex;
display: -o-flex;
display: flex;
}
div{
.flexbox();//使用
}
我已经把与伸缩盒相关的东西都封装为一个less库,大家可以到这里下
// display: flex
.flexbox() {
// 2009 spec
display: -webkit-box;
display: -moz-box;
display: -o-box;
// tweener
display: -webkit-flexbox;
display: -moz-flexbox;
display: -ms-flexbox;
display: -o-flexbox;
// new spec
display: -webkit-flex;
display: -moz-flex;
display: -ms-flex;
display: -o-flex;
display: flex;
}
// flex //
.flex(@flex) {
-webkit-box-flex: @flex;
-moz-box-flex: @flex;
-o-box-flex: @flex;
box-flex: @flex;
-webkit-flex: @flex;
-moz-flex: @flex;
-ms-flex: @flex;
-o-flex: @flex;
flex: @flex;
}
@flexvalue: 1 1 auto;
// flex-derection = box-orient + box-direction
.flex-direction(@direction) when (@direction = row) {
-webkit-box-orient: horizontal;
-moz-box-orient: horizontal;
-webkit-flex-direction: row;
-moz-flex-direction: row;
-ms-flex-direction: row;
flex-direction: row;
}
.flex-direction(@direction) when (@direction = row-reverse) {
-webkit-box-orient: horizontal;
-moz-box-orient: horizontal;
-webkit-box-direction: reverse;
-moz-box-direction: reverse;
-webkit-flex-direction: row-reverse;
-moz-flex-direction: row-reverse;
-ms-flex-direction: row-reverse;
flex-direction: row-reverse;
}
.flex-direction(@direction) when (@direction = column) {
-webkit-box-orient: vertical;
-moz-box-orient: vertical;
-webkit-flex-direction: column;
-moz-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
}
.flex-direction(@direction) when (@direction = column-reverse) {
//http://www.w3school.com.cn/cssref/pr_box-orient.asp
-webkit-box-orient: vertical;
-moz-box-orient: vertical;
-webkit-box-direction: reverse;
-moz-box-direction: reverse;
-webkit-flex-direction: column-reverse;
-moz-flex-direction: column-reverse;
-ms-flex-direction: column-reverse;
flex-direction: column-reverse;
}
.flex-direction(@direction) {
-webkit-flex-direction: @direction;
-moz-flex-direction: @direction;
-ms-flex-direction: @direction;
-o-flex-direction: @direction;
flex-direction: @direction;
}
// order //
.order(@order) {
-webkit-box-ordinal-group: @order + 1;
-moz-box-ordinal-group: @order + 1;
-o-box-ordinal-group: @order + 1;
-webkit-order: @order;
-moz-order: @order;
-ms-order: @order;
-o-order: @order;
order: @order;
}
//justify content//
//2009 property is box-pack
//2009 property does not support a method for space-around
//start
//end
//center
//justify
.justify-content(@justify-method) when (@justify-method = flex-start) {
-webkit-box-pack: start;
-moz-box-pack: start;
-ms-flex-pack: start;
-o-box-pack: start;
box-pack: start;
justify-content: flex-start;
}
.justify-content(@justify-method) when (@justify-method = flex-end) {
-webkit-box-pack: end;
-moz-box-pack: end;
-ms-flex-pack: end;
-o-box-pack: end;
box-pack: end;
justify-content: flex-end;
}
.justify-content(@justify-method) when (@justify-method = center) {
-webkit-box-pack: center;
-moz-box-pack: center;
-ms-flex-pack: center;
-o-box-pack: center;
box-pack: center;
justify-content: center;
}
.justify-content(@justify-method) when (@justify-method = space-between) {
-webkit-box-pack: justify;
-moz-box-pack: justify;
-ms-flex-pack: justify;
-o-box-pack: justify;
box-pack: justify;
justify-content: space-between;
}
// note there is no fallback 2009 spec support for space-around
.justify-content(@justify-method) when (@justify-method = space-around) {
-webkit-box-pack: justify;
-moz-box-pack: justify;
-ms-flex-pack: distribute;
-o-box-pack: justify;
box-pack: justify;
justify-content: space-around;
}
// 2011 spec
// flex-start (default): items are packed toward the start line
// flex-end: items are packed toward to end line
// center: items are centered along the line
// space-between: items are evenly distributed in the line; first item is on the start line, last item on the end line
// space-around: items are evenly distributed in the line with equal space around them
.justify-content(@justify-method) {
-webkit-justify-content: @justify-method;
-moz-justify-content: @justify-method;
-ms-justify-content: @justify-method;
-o-justify-content: @justify-method;
justify-content: @justify-method;
}
.align-items(@align-method) when (@align-method = flex-start ){
-moz-box-align: start ;//https://developer.mozilla.org/en-US/docs/Web/CSS/box-align
-webkit-box-align: start ;
-ms-flex-align: start;//http://realworldvalidator.com/css/module/Microsoft/-ms-flex-align
-webkit-align-items: flex-start;
align-items: flex-start;
}
.align-items(@align-method) when (@align-method = flex-end ){
-moz-box-align: end;
-webkit-box-align: end;
-ms-flex-align: end;
-webkit-align-items: flex-end;
align-items: flex-end;
}
.align-items(@align-method) when (@align-method = center ){
-moz-box-align: center;
-webkit-box-align: center;
-ms-flex-align: center;
-webkit-align-items: center;
align-items: center;
}
.align-items(@align-method) when (@align-method = baseline ){
-moz-box-align: baseline;
-webkit-box-align: baseline;
-ms-flex-align: baseline;
-webkit-align-items: baseline;
align-items: baseline;
}
.align-items(@align-method) when (@align-method = stretch ){
-moz-box-align: stretch;
-webkit-box-align: stretch;
-ms-flex-align: stretch;
-webkit-align-items: stretch;
align-items: stretch;
}
.align-items(@align-method){
-moz-box-align: @align-method;
-webkit-box-align: @align-method;
-ms-flex-align: @align-method;
-webkit-align-items: @align-method;
align-items: @align-method;
}
.flex-wrap(@wrap-method) when(@wrap-method = nowrap){
-ms-flex-wrap:none;
-moz-flex-wrap:nowrap;
-webkit-flex-wrap: nowrap;
flex-wrap: nowrap;
}
.flex-wrap(@wrap-method) when(@wrap-method = wrap){
-ms-flex-wrap:wrap;
-moz-flex-wrap:wrap;
-webkit-flex-wrap: wrap;
flex-wrap: wrap;
}
.flex-wrap(@wrap-method) when(@wrap-method = wrap-reverse){
-ms-flex-wrap:wrap-reverse;
-moz-flex-wrap:wrap-reverse;
-webkit-flex-wrap: wrap-reverse;
flex-wrap: wrap-reverse;
}
.flex-wrap(@wrap-method){
-ms-flex-wrap:@wrap-method;
-moz-flex-wrap:@wrap-method;
-webkit-flex-wrap:@wrap-method;
flex-wrap:@wrap-method;
}
.align-self(@value) when(@value = flex-start){
-webkit-align-self: flex-start;
-ms-flex-item-align: start;
align-self: flex-start;
}
.align-self(@value) when(@value = flex-end){
-webkit-align-self: flex-end;
-ms-flex-item-align: end;
align-self: flex-end;
}
.align-self(@value) when(@value = center){
-webkit-align-self: center;
-ms-flex-item-align: center;
align-self: center;
}
.align-self(@value) when(@value = baseline){
-webkit-align-self: baseline;
-ms-flex-item-align: baseline;
align-self: baseline;
}
.align-self(@value) when(@value = stretch){
-webkit-align-self: stretch;
-ms-flex-item-align: stretch;
align-self: stretch;
}
.align-self(@value){
-webkit-align-self:@value;
-ms-flex-item-align:@value;
lign-self:@value
}
//===========================================================
// http://stackoverflow.com/questions/15662578/flexible-box-model-display-flex-box-flexbox by RubyLouvre
.user-select(){
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.fixed-width(@value){
width:@value;
min-width:@value;
max-width:@value;
}
.fixed-height(@value){
height:@value;
min-height:@value;
max-height:@value;
}
.box-sizing(@value){
-webkit-box-sizing: @value; /* Safari/Chrome, other WebKit */
-moz-box-sizing:@value; /* Firefox, other Gecko */
box-sizing: @value; /* Opera/IE 8+ */
}
.brimming(){
width: 100%;
height: 100%;
}
.transform(@value){
transform:@value;
-moz-transform:@value;
-webkit-transform:@value;
-ms-transform:@value;
}
.box-shadow(@value){
-webkit-box-shadow: @value;
-moz-box-shadow: @value;
-ms-box-shadow:@value;
box-shadow:@value;
}
//=========================================================
css3伸缩布局属性总结的更多相关文章
- CSS3 伸缩布局盒模型记
CSS3 伸缩布局盒模型 CSS3引入的布局模式Flexbox布局,主要思想是让容器有能力让其子项目能够改变其宽度,高度,以最佳方式填充可用空间.Flex容器使用Flex项目可以自动放大与收缩,用来填 ...
- css3伸缩布局中justify-content详解
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- CSS3 伸缩布局盒模型
CSS3引入的布局模式Flexbox布局,主要思想是让容器有能力让其子项目能够改变其宽度,高度,以最佳方式填充可用空间.Flex容器使用Flex项目可以自动放大与收缩,用来填补可用的空闲空间.更重要的 ...
- CSS3——伸缩布局及应用
CSS3在布局方面做了非常大的改进,使得我们对块级元素的布局排列变得十分灵活,适应性非常强,其强大的伸缩性,在响应式开中可以发挥极大的作用. 主轴:Flex容器的主轴主要用来配置Flex项目,默认是水 ...
- CSS3伸缩布局Flex学习笔记
如果需要使用伸缩布局首先得把display:flex;对于兼容还得加前缀display:-webkit-display:flex;等其他浏览器前缀,但我本机Chrome测试已经不需要加前缀了,其实这些 ...
- css3 伸缩布局 display:flex等
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 第 29 章 CSS3 弹性伸缩布局[下]
学习要点: 1.新版本 主讲教师:李炎恢 本章主要探讨 HTML5 中 CSS3 提供的用来实现未来响应式弹性伸缩布局方案,这里做一个初步的了解. 一.新版本 新版本的 Flexbox 模型是 201 ...
- 第 29 章 CSS3 弹性伸缩布局[中]
学习要点: 1.混合过度版 主讲教师:李炎恢 本章主要探讨 HTML5 中 CSS3 提供的用来实现未来响应式弹性伸缩布局方案,这里做一个初步的了解. 一.混合过渡版 混合版本的 Flexbox 模型 ...
- 第 29 章 CSS3 弹性伸缩布局[上]
学习要点: 1.布局简介 2.旧版本 主讲教师:李炎恢 本章主要探讨 HTML5 中 CSS3 提供的用来实现未来响应式弹性伸缩布局方案,这里做一个初步的了解. 一.布局简介 CSS3 提供一种崭新的 ...
随机推荐
- [转]深入理解学习GIT工作流
深入理解学习Git工作流 字数13437 阅读2761 评论3 喜欢70 个人在学习git工作流的过程中,从原有的 SVN 模式很难完全理解git的协作模式,直到有一天我看到了下面的文章,好多遗留在心 ...
- M2: XAML Controls(2)
在前小节中,我们在Card程序的主界面中加入了简单的XAML控件, 本小节将在其基础上进行优化,使界面看上去更加美观.本小节用到了Grid Control, Border Control,以及XAML ...
- Git 使用juju
写在前面: 想不到好标题,就写好文章吧. 此篇主要是介绍在使用git过程中常见的一些命令以及遇到的问题,手册+答疑解惑! 在git未玩得通透熟练之际,此篇文章的标题序号无任何意义. 1.git 版本回 ...
- [读书笔记]OSGI-灵活的类加载器架构
以下内容来自周志明的<深入理解Java虚拟机>. 学习JEE规范,去看JBoss源码:学习类加载器,就去看OSGI源码. OSGI,即Open Service Gateway Initia ...
- UVa 二叉树重建(先序+中序求后序)
题意是给出先序和中序,求出后序. 先序遍历先访问根结点,通过根结点可以在中序中把序列分为左子树部分和右子树部分,我建了一个栈,因为后序遍历最后访问根结点,所以把每次访问的根结点放入栈中.因为后序遍历先 ...
- 用正则从html代码中提取图片路径
$str = '<div align="center"> <img src="http://www.99tyg.com/public/images/e8 ...
- 一些上流的CSS3图片样式
直接在图片元素上直接应用CSS3 inset box-shadow 或 border-radius时,浏览器并不能完美的渲染它们.不过,如果把这个图片用作背景图,你就可以可以给它添加任何样式了,浏览器 ...
- Jetty与Tomcat的区别 转
Jetty与Tomcat的区别 由于没有研究过Tomcat,所以区别不好说,这里暂时就网上的一些言论和自己所了解到的一些总结下(摘自于许令波). Jetty 的架构从前面的分析可知,它的所有组件都是基 ...
- WPF ListBox响应鼠标滚轮
public static T FindVisualChild<T>(DependencyObject obj) where T : DependencyObject { if (obj ...
- NSIS使用记录
; 该脚本使用 HM VNISEdit 脚本编辑器向导产生 ; 安装程序初始定义常量 !define PRODUCT_NAME "" !define PRODUCT_VERSION ...