flex布局的详细使用,文字加图片 | 您所在的位置:网站首页 › div怎么加文字 › flex布局的详细使用,文字加图片 |
flex两个概念:flex container 、flex items
flex布局中没有x、y轴,flex布局中只有main axis(主轴),cross axis(交叉轴)。 未启动flex布局: 1 2 3 .box { width: 500px; height: 300px; margin: 0 auto; background-color: orange; } .item { width: 100px; height: 100px; color: white; } .item1 { background-color: red; } .item2 { background-color: black; } .item3 { background-color: yellow; }效果: flex-direction: 默认flex-direction: row,flex-direction的作用是决定main axis的方向。上面的排布方式也是因为flex-direction: row。 flex-direction的取值有4钟: 箭头表示main axis的走向 取值效果row从左到右 →row-reverse从右到左←column从左上到左下↓column-reverse从左下到上↑比如当box样式为: .box { width: 500px; height: 300px; margin: 0 auto; background-color: orange; display: flex; /在父容器中输入display: flex就是启动了flex布局/ flex-direction: row-reverse; } 效果: ![]() ![]() ![]() ![]() ![]() ![]() align-items: 决定flex items在cross axis上的对其方式。 align-items取值: 取值效果normal默认方式,注意这里的box属性中的height=100px取消了,这里进行了拉升拉伸。![]() ![]() ![]() ![]() ![]() flex-wrap: 决定是flex container单行还是多行 这里需要改变一下html布局:多添加几个items 在css样式中也将items的高度变回100px,.box的样式的宽度由500改成550 1 2 3 4 5 6 7 8 9 10 11 12 .box { width: 550px; height: 300px; margin: 50px auto; background-color: orange; display: flex; /*在父容器中输入display: flex就是启动了flex布局*/ flex-wrap: nowrap; } .item { width: 100px; /* height: 100px; */ color: white; } .item1 { background-color: red; height: 100px; } .item2 { background-color: black; height: 100px; } .item3 { background-color: yellow; height: 100px; }flex-wrap取值: 取值效果nowrap默认单行![]() ![]() ![]() flex-flow: flex-flow是flex-direction和flex-wrap的简写,可以简略,顺序任意. 1 2 3 4 5 6 7 .box { width: 550px; height: 300px; margin: 50px auto; background-color: orange; display: flex; /*在父容器中输入display: flex就是启动了flex布局*/ justify-content: space-evenly; flex-flow: row wrap; /* align-content: flex-start; */ } .item { width: 100px; /* height: 100px; */ color: white; } .item1 { background-color: red; height: 100px; } .item2 { background-color: black; height: 100px; } .item3 { background-color: yellow; height: 100px; }
![]() ![]() ![]() ![]() ![]() ![]() order: 决定flex items的排序。 可以设置任意数值,整数,0,数值越小排在越前面。 默认0。 1 2 3 .box { width: 550px; height: 300px; margin: 50px auto; background-color: orange; display: flex; /*在父容器中输入display: flex就是启动了flex布局*/ } .item { width: 100px; /* height: 100px; */ color: white; } .item1 { background-color: red; height: 100px; order: 15000000; } .item2 { background-color: black; height: 100px; order: 3; } .item3 { background-color: yellow; height: 100px; order: 10000; }
flex-grow: .item { width: 100px; /* height: 100px; */ color: white; } .item1 { background-color: red; height: 100px; flex-grow: 1; } .item2 { background-color: black; height: 100px; flex-grow: 1; } .item3 { background-color: yellow; height: 100px; }设置flex-grow前: 效果: flex-basis: 用来设置flex、items在main axis方向上的base size, 默认值:auto。 决定flex items最终base size的因素,优先级高到低: max-width、max-height、min-width、min-height。flex-basis。width、height。内容本身的size。 1 2 3 .box { width: 500px; height: 300px; margin: 50px auto; background-color: orange; display: flex; /*在父容器中输入display: flex就是启动了flex布局*/ } .item { width: 100px; /* height: 100px; */ color: white; } .item1 { background-color: red; height: 100px; flex-basis: 300px; } .item2 { background-color: black; height: 100px; } .item3 { background-color: yellow; height: 100px; }
|
CopyRight 2018-2019 实验室设备网 版权所有 |