CSS样式中 Flexbox 布局模块-弹性布局

本文详细介绍了如何使用Flexbox布局技术简化HTML和CSS代码,包括设置浏览器版本、无flexbox时的布局示例,以及各种flex容器属性如flex-direction、justify-content和align-items的应用。
摘要由CSDN通过智能技术生成

*作用:简化代码操作,不用再使用浮动或者定位。

1.确定浏览器版本 

2.在未使用flexbox布局时:

<div class="flex1">
    <div class="flex2">1</div>
    <div class="flex2">2</div>
    <div class="flex2">3</div>
</div>


<style>
    .flex1{
        background-color: blue;
    }
    .flex2{
        width: 50px;
        height: 50px;
        border: 1px solid black;
        background-color:antiquewhite;
    }
</style>

 3.当在外部容器 添加 display:flex 时:

                布局发生改变,横向布局,比原先写法更加简单。

 

  4.flex 容器属性
属性名称参数描述
flex-direction column设置垂直堆叠 flex 项目(从上到下)
column-reverse垂直堆叠 flex 项目(但从下到上)
row(从左到右)
row-reverse水平堆叠 flex 项目(但从右到左)
flex-wrapwrap规定 flex 项目将在必要时进行换行
wrap-reverse弹性项目将以相反的顺序换行
flex-flow先direction后wrap属性是用于同时设置 flex-direction 和 flex-wrap 属性的简写属性
justify-contentcenter将 flex 项目在容器的中心对齐
flex-start将 flex 项目在容器的开头对齐(默认)
flex-end将 flex 项目在容器的末端对齐
space-around显示行之前、之间和之后带有空格的 flex 项目
space-between 显示行之间有空格的 flex 项目
align-itemscenter将 flex 项目在容器中间对齐
flex-start将 flex 项目在容器顶部对齐
flex-end将弹性项目在容器底部对齐
stretch拉伸 flex 项目以填充容器(默认)
baseline使 flex 项目基线对齐
align-contentspace-between 显示的弹性线之间有相等的间距
space-around显示弹性线在其之前、之间和之后带有空格
stretch拉伸弹性线以占据剩余空间(默认)
center在容器中间显示弹性线
flex-start在容器开头显示弹性线
flex-end在容器的末尾显示弹性线

        1.flex-direction: column-reverse;

        

        2.flex-direction: row;

         

        3. flex-direction: row-reverse;

        

         4.flex-wrap:wrap;

        

        5.flex-wrap:wrap-reverse;

         

        6.justify-content:center;

                 

        7.justify-content:flex-start;

        

        8.justify-content:space-around;

         

        9.justify-content:space-between;

        

        10.align-items:center;

        

        11.align-items:flex-start;

        

         

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值