flex布局

flex布局

容器的属性

flex-direction属性

flex-wrap属性 

flex-flow属性

justify-content属性

align-items属性

align-content属性


flex布局

Flex 是 Flexible Box 的缩写,意为"弹性布局",用来为盒状模型提供最大的灵活性。

任何一个容器都可以指定为 Flex 布局。

.box{
  display: flex;
}

行内元素也可以使用 Flex 布局。


.box{
  display: inline-flex;
}

Webkit 内核的浏览器,必须加上-webkit前缀。


.box{
  display: -webkit-flex; /* Safari */
  display: flex;
}

注意,设为 Flex 布局以后,子元素的floatclearvertical-align属性将失效。

容器的属性

以下6个属性设置在容器上。

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

flex-direction属性

 通过给父盒子添加flex属性,来控制子盒子的位置和排列方式

flex-direction属性决定主轴的方向(即项目的排列方向)。

  • row(默认值):主轴为水平方向,起点在左端。
  • row-reverse:主轴为水平方向,起点在右端。
  • column:主轴为垂直方向,起点在上沿。
  • column-reverse:主轴为垂直方向,起点在下沿。
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<style>
    .flex1 {
        display: flex;
        display: -webkit-flex;
      
    }
    
    div {
        margin: 5px;
        height: 50px;
        background: yellow;
        flex: 1;
    }
    
    .row {
        flex-direction: row;
    }
    
    .row-reverse {
        flex-direction: row-reverse;
    }
    
    .column {
        flex-direction: column;
    }
    
    .column-reverse {
        flex-direction: column-reverse;
    }
</style>

<body>
    <section class="flex1 row">
        <div>1 flex-direction:row(默认值):主轴为水平方向,起点在左端</div>
        <div>2</div>
        <div>3</div>
    </section>
    <br/>
    <br/>
    <br/>
    <section class="flex1 row-reverse">
        <div>1 row-reverse:主轴为水平方向,起点在右端</div>
        <div>2</div>
        <div>3</div>
    </section>
    <br/>
    <br/>
    <br/>
    <section class="flex1 column">
        <div>1 column:主轴为垂直方向,起点在上沿 </div>
        <div>2</div>
        <div>3</div>
    </section>
    <br/>
    <br/>
    <br/>
    <section class="flex1 column-reverse">
        <div>1 column-reverse:主轴为垂直方向,起点在下沿 </div>
        <div>2</div>
        <div>3</div>
    </section>
</body>

</html>

flex-wrap属性 

flex-flow属性

justify-content属性

align-items属性

align-content属性

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

cutelady0927

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值