赞
踩
对容器进行display: flex布局之后,可通过justify-content来调整容器中子元素整体的布局的位置,其值分别有如下几个:
注:以下情况均由主轴为从左到右方向进行,其从下到上的主轴情况原理类似
/* align-items: flex-start; */
justify-content: flex-start;
效果-水平-开头
center
设置为center值之后,其子元素整体的位置则是在主轴的中心位置,其效果如下:
align-items: center; // 垂直居中
效果-水平-中心
justify-content: center; //水平-居中
效果
flex-end
其flex-end则是在主轴的右边位置,效果如下图所示:
align-items: flex-end; // 垂直结尾
效果-水平-结尾
justify-content: flex-end // 水平结尾
效果
justify-content: space-around; // 中间间隔
justify-content: space-between; // 两边撑开
代码
即默认状态下的在侧轴的上边位置,页面代码如下: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> #container { display: flex; margin: 0px auto; width: 800px; height: 400px; background-color: purple; align-items: flex-start; /* align-items: center; */ /* align-items: flex-end; */ } .item { background-color: pink; margin-left: 10px; margin-top: 10px; width: 250px; height: 100px; } </style> </head> <body> <div id="container"> <div class="item">1</div> <div class="item">2</div> <div class="item">3</div> <div class="item">4</div> </div> </body> </html>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。