美文网首页前端
前端布局方式之(flex弹性盒子模型)与兼容

前端布局方式之(flex弹性盒子模型)与兼容

作者: 一生悬命Cat | 来源:发表于2019-03-24 17:27 被阅读25次

容器的属性

flex-direction
flex-wrap
flex-flow
justify-content
align-items
align-content

1.flex-direction属性

(flex-direction:row)


row.png

(flex-direction:row-reverse)


row-reverse.png

(flex-direction:column)


column.png

(flex-direction:column-reverse)


column-reverse.png

*兼容性
新写法flex-direction的兼容

image

旧写法box-orient和box-direction兼容一样的

image

可以看出,ie11下版本还是不支持方向这属性,其他浏览器要加前缀,所以当要定义方向时这个兼容可以写成

<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; 
word-wrap: break-word; font-family: &quot;Courier New&quot; !important; 
font-size: 12px !important;">
    -webkit-box-orient:vertical;
    -webkit-box-direction:normal;
    -moz-box-orient:vertical;
    -moz-box-direction:normal;
    flex-direction:column;
    -webkit-flex-direction:column;
</pre>
___________________________________________________
达到flex-direction:row/row-reverse效果
   box-orient:horizontal
   box-direction:normal/reverse

达到flex-direction:column/column-reverse效果
   box-orient:vertical 
   box-direction:normal/reverse

2.flex-wrap属性

(flex-wrap:nowrap)


nowrap.png

(flex-wrap:wrap)


wrap.png

(flex-wrap-reverse)


wrap-reverse.png

*兼容性
定义子元素换行情况

新写法flex-wrap 兼容如下

image

旧写法box-lines:single/multiple(盒子行数:单行/多行)
默认single 兼容如下

image

ie11下还是不支持此属性,上面firefox不支持但在25版本后是支持的,还是要用flex加-moz, 比较直观所以定义子元素换行时 可以如下写法

<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; 
word-wrap: break-word; font-family: &quot;Courier New&quot; !important;
 font-size: 12px !important;"> 
  -webkit-flex-wrap:wrap;
    -webkit-box-lines:multiple;
    -moz-flex-wrap:wrap;
    flex-wrap:wrap;</pre>

3.flex-flow属性

上面两个属性的合写

.box {
  flex-flow: <flex-direction> <flex-wrap>;
}

4.justify-content

(定义了主轴对齐方式)
(justify-content:center)


center.png

(justify-content:flex-start)


start.png

(justify-content:flex-end)


end.png

(justify-content:space-between)


between.png

(justify-content:space-around)


around.png

*兼容性
横向排列布局

新版本justify-content的兼容情况

image

旧版本box-pack的兼容情况

image

故兼容可写成:

<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; 
word-wrap: break-word; font-family: &quot;Courier New&quot; !important; 
font-size: 12px !important;">
-webkit-justify-content:center;
justify-content:center;
-moz-box-pack:center;
-webkit--moz-box-pack:center;
box-pack:center;
</pre>

5.align-items

align-items属性定义项目在交叉轴上如何对齐。
(align-items: flex-start)


align-items: flex-start

(align-items: flex-end)


align-items: flex-end

(align-items: center)


align-items: center

(align-items:stretch)


align-items:stretch

(align-items:baseline)
项目的第一行文字的基线对齐。

baseline.png
竖向排列布局

新版本align-items兼容情况

image

旧版本box-align的兼容情况

image

故兼容性可写成:

<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: &quot;Courier New&quot; !important; font-size: 12px !important;">align-items:center;
-webkit-align-items:center;
box-align:center;
-moz-box-align:center;
-webkit-box-align:center;</pre>

6.align-content

align-content属性定义了多根轴线的对齐方式。如果项目只有一根轴线,该属性不起作用。

.box {
  align-content: flex-start | flex-end | center | space-between | space-around | stretch;
}

(align-content:center)


(align-content:center).png

(align-content:flex-start)


align-content:flex-start.png
(align-content:space-between)
spacebetween.png

(align-content:space-around)


spacearound.png

(align-content:stretch)


stretch.png

*伸缩盒子兼容
伸缩盒子布局兼容

新版本flex:num兼容

image

旧版本box-flex兼容

image

故兼容性可写成

<pre style="margin: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: &quot;Courier New&quot; !important; font-size: 12px !important;">box-flex:num;
-webkit-box-flex:num;
-moz-box-flex:num;
flex:num;
-webkit-flex:num;</pre>

相关文章

  • 前端布局方式之(flex弹性盒子模型)与兼容

    容器的属性 flex-directionflex-wrapflex-flowjustify-contentalig...

  • flex布局

    1、什么是flex布局? flex布局又叫弹性布局,弹性盒子,与怪异和模型布局不同,其布局能更精准。 2、如何设置...

  • 弹性盒子--Flexbox布局!!

    弹性盒子布局模型 1. Flex布局是什么? Flex是发了flexbox 的缩写,意为“弹性布局”,用来为盒子状...

  • flex弹性布局

    flex弹性布局与传统布局的区别 传统布局优点:兼容性好缺点:繁琐 flex弹性布局优点: 简单缺点:兼容性不好 ...

  • React Native - Flex布局

    React Native - Flex布局 Flex布局概述 概念:弹性盒子布局 历史:性盒模型,该布局方案由W3...

  • display: flex;弹性布局

    flex弹性布局用于盒子模型,设为Flex布局以后,子元素的float、clear和vertical-align属...

  • flex布局笔记

    Flex 布局 简介 flex 布局 (Flexible 布局,弹性盒子)是在小程序开发经常使用的布局方式 官方文...

  • css flex

    flex介绍 flex是弹性盒布局的意思,用来为盒子模型提供灵活性。采用flex布局的盒子叫做容器,它的子元素叫做...

  • flex

    弹性盒子布局 参考 阮一峰老师 兼容性 设置为弹性盒子display: flex 要加上浏览器的前缀。设置为弹性盒...

  • flex布局(弹性布局)浅析

    1.Flex布局是什么? Flex是Flexible Box的缩写,就是灵活的弹性页面布局。 作用是为盒子模型提供...

网友评论

    本文标题:前端布局方式之(flex弹性盒子模型)与兼容

    本文链接:https://www.haomeiwen.com/subject/tlvuvqtx.html