博主信息
博文 10
粉丝 0
评论 0
访问量 7002
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
flex容器与项目常用的6个属性
P粉854918706
原创
747人浏览过

flex容器与项目常用的6个属性

flex容器必知3个属性

  • flex-flow:主轴和是否换行

    • 主轴:row(默认值) 和 column

    • 换行:wrap或者nowrap(默认值)

  • place-content:项目排列和剩余空间分配方式

    • start(默认)  end 分别表示项目排列首末两端

    • center 项目居中,剩余空间左右分布

    • space-between 两端对齐(3个项目2个对等剩余空间)

    • space-around  项目两侧空间相同(3个项目2组2个对等,中间2个等于外侧两个的2倍)

    • space-evenly  平均对齐(3个项目4个对等剩余空间)

  • place-items:项目在交叉轴上的对齐方式

    • stretch 自动伸展 默认

    • start  end  上对齐和下对齐

flex项目必知3个属性

  • flex:三个参数,放大因子   收缩因子   计算参数

    • 项目设置参数的优先级:min-width>flex.width>width

    • 0 1 auto 是默认值或者用initial

    • 1 1 auto 可以直接省略用auto或者1

    • 0 0 auto 可以用none

  • order:默认值是0,项目排序调整

    • 数值越大,位置越靠后

  • place-self:单个项目对齐

    • start   end

示例代码:

<!DOCTYPE html><html lang="zh-CN"><head>    <meta charset="UTF-8">    <meta http-equiv="X-UA-Compatible" content="IE=edge">    <meta name="viewport" content="width=device-width, initial-scale=1.0">    <title>Document</title></head><body>    <!-- flex容器必知3个属性: -->    <div class="box">        <div class="hello">hello1</div>        <div class="hello">hello2</div>        <div class="hello">hello3</div>    </div>    <style>        * {            margin:0;            padding:0;            box-sizing: border-box;        }        .box{            border:3px solid red;            height:20em;            display: flex;            place-content: space-between;            place-content: space-around;            place-content: space-evenly;            place-items: stretch;            /* flex-flow: column nowrap; */        }        .box .hello{            border:1px dashed green;            margin:10px;            /* min-width:20em; */            text-align: center;            flex:1 1 auto;            /* flex:initial */        }        .box .hello:first-of-type{            background-color: aqua;            order:3;        }        .box .hello:last-of-type{            background-color: coral;            order:-1;            place-self: start;        }    </style></body></html>

批改老师:PHPzPHPz

批改状态:合格

老师批语:
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
作者最新博文
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学