css弹性盒模型学习

开启盒模型:加入display:flex这句话就开启

/*行内弹性盒子*/

display: inline-flex;

flex-direction:设置flex的排序属性,默认为行:row

可设置 flex-direction: row;flex-direction: row-reverse;

flex-direction: column-reverse;  flex-direction: column;

添加reverse表示翻转,效果如下


默认row排列


翻转row排列

flex-wrap: 该属性控制元素内容装不下时是否换行:(该属性也有翻转属性-reverse)

在不换行(默认)时,元素的内容会随之变小


不换行

在加了换行后元素会换行显示

换行

justify-content:该属性设置元素在主轴的排列

/* 排列方式对齐到主轴的开始、 */

            /* justify-content: flex-start; */

            /* 排列方式对齐到主轴的结束、 */

            justify-content: flex-end;

            /* 居中、 */          

               justify-content: center;

    /* 左右紧挨边缘,其余平均分布 */ 

      justify-content: space-between;   

    /* 绝对平均分布 */ 

           justify-content: space-evenly;       


justify-content: flex-start


 justify-content: flex-end


 justify-content: center


      justify-content: space-between;


justify-content: space-evenly

align-items:该属性设置交叉轴的对齐方式(单行元素)

            align-items: flex-end;

            align-items: flex-start;

            align-items: center;


align-items: flex-end


align-items: flex-start;


align-items: center

align-content:该属性设置侧轴多行时,它们的对齐方式

            align-content: flex-start;

            align-content: flex-end;

            align-content: center;

            align-content: space-between;

            align-content: space-evenly;


align-content: flex-start;


align-content: flex-end;


align-content:center


align-content: space-between;


align-content: space-evenly;

flex-grow:元素可用空间分配

article div:nth-child(1) {

            flex-grow: 0;

        }


        article div:nth-child(2) {

            flex-grow: 2;

        }


        article div:nth-child(3) {

            flex-grow: 4;

        }

flex-grow:

用以上属性简写布局

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <meta name="viewport" content="width=device-width, initial-scale=1.0">    <title>Document</title>    <style>        * {            margin: 0;            padding: 0;        }                body {            height: 100vh;            display: flex;            flex-direction: column;        }                header {            background-color: teal;            height: 100px;        }                main {            background-color: crimson;            flex-grow: 1;            display: flex;        }                footer {            background-color: teal;            height: 100px;        }                main div:nth-child(1) {            background-color: turquoise;            flex-grow: 1;        }                main div:nth-child(2) {            background-color: rgb(177, 19, 106);            flex-grow: 5;        }                main div:nth-child(3) {            background-color: turquoise;            flex-grow: 1;        }    </style></head><body>    <header></header>    <main>        <div>left</div>        <div>main</div>        <div>right</div>    </main>    <footer></footer></body></html>



弹性布局


order:元素排序属性,值越大,元素排序越靠后

order属性
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 主轴方向 /* 在伸缩布局中, 默认伸缩项是从左至右的排版的 */ displ...
    韦栋阅读 4,631评论 1 0
  • flex 布局是 css3 中使用最频繁也是最出色的功能,有点复杂,分为应用在容器上的属性和项目上的属性,即父元素...
    LaBaby_阅读 2,900评论 0 0
  • 关于css常见问题,大多是移动端的。 简单的排版规则:条目与条目之间空两行,每条内容部分分段空一行。标点符号全部用...
    苏水儿阅读 10,457评论 0 9
  • 第一章 复杂选择器 一、兄弟选择器:具备相同父元素的元素 ① 特点:1、通过位置关系来匹配元素(平级关系) ...
    fastwe阅读 4,147评论 0 0
  • (这是15年初学css时记的笔记) 选择器 简单选择器 标签选择器 直接把标签名加前面。 类选择器 用.+ cla...
    burningalive阅读 4,652评论 0 0