2020-12-24

本文详细介绍了Flex布局中flex-direction和justify-content、align-items属性的使用,展示了如何通过空间分布对齐实现不同视觉效果,包括行向布局反转、均匀分布和居中对齐等。
摘要由CSDN通过智能技术生成

Flex布局

在这里插入图片描述

flex container容器属性

  • flex-direction:row(默认) row-reverse(沿行方向从左往右)
  • column-reverse:(沿列方向从下往上)
      flex-direction: row;
     **flex-direction: column-revers**e;

在这里插入图片描述

  • Justify-content:决定了flex-items在main axios上的对齐方式。
    默认值justify-content:flex-start。
    在这里插入图片描述
    当justify-content: flex-end;时,变成右对齐
    在这里插入图片描述
    当调整justify-content: space-between;时,效果如下
    在这里插入图片描述
    当调整justify-content: space-evenly;效果如下
    在这里插入图片描述

  • align-items决定了item在交叉轴的对齐方式。

                    **aliign-items:center时,效果如下**
    

在这里插入图片描述

在这里插入代码片
``````html
<!-- flex布局 -->

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
 <div class="Box">
    <div class="item item1">item1</div>
     <div class="item item2">item2</div>
     <div class="item item3">item3</div>
 </div>
<strong>Strong元素</strong>
</body>
<style>
    .Box{
        /* 开启flex布局 inline-flex
        flex : 块级元素   inline-flex:行内元素。
        */
        display:  flex;
        width: 500px;
        height: 300px;
        background-color: #ff0000 ;
        /*flex-direction: row-reverse;*/

        margin: 0 auto;
        justify-content: space-evenly;
        align-items:center;
    }
    .item{
        width: 100px;
        /*height: 100px;*/
        color: white;
        text-align: center;
        /*line-height: 100px;*/
    }
    .item1{
        background-color: yellow;
        height: 100px;
        line-height: 100px;
    }
    .item2{
        background-color: green ;
        height: 150px;
        line-height: 150px;
    }
    .item3{
        background-color: blue;
        height: 200px;
        line-height: 200px;
    }

</style>
</html>



![](https://img-blog.csdnimg.cn/20201224204534800.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQ1NDg5MjI1,size_16,color_FFFFFF,t_70)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值