justify-content属性

justify-content 用于设置或检索弹性盒子元素在主轴方向上的对齐方式。

属性值:flex-start

属性值:flex-end

属性值:center

属性值:space-between

属性值:space-around

通过具体代码示例各个属性值的效果。

HTML结构

<div class="container flex">
   <div class="items">A</div>
   <div class="items">B</div>
   <div class="items">C</div>
   <div class="items">D</div>
   <div class="items">E</div>
   <div class="items">F</div>
   <div class="items">G</div>
   <div class="items">H</div>
</div>

CSS样式:

.container {
    display: flex;
    width: 1000px;
    height: 500px;
    background-color: gray;
    margin: 20px auto;
}

.items {
    width: 300px;
    height: 100px;
    text-align: center;
    line-height: 100px;
    font-weight: 900;
    color: gray;
}

.items:nth-child(1) {
    background-color: #ff0000;
}

.items:nth-child(2) {
    background-color: #ffff00;
}

.items:nth-child(3) {
    background-color: #ff00ff;
}

.items:nth-child(4) {
    background-color: #0000ff;
}

.items:nth-child(5) {
    background-color: #14a9ee;
}

.items:nth-child(6) {
    background-color: #71a03b;
}

.items:nth-child(7) {
    background-color: #c323eb;
}

.items:nth-child(8) {
    background-color: #ffffff;
}

 

属性值:flex-start

描述:默认值。项目位于容器的开头。

.flex {
    flex-wrap: wrap;
    justify-content: flex-start;
}

jusitify-content:flex-start;

属性值:flex-end

描述:项目位于容器的结尾。

.flex {
    flex-wrap: wrap;
    justify-content: flex-end;
}

属性值center

描述:项目位于容器的中心。

.flex {
    flex-wrap: wrap;
    justify-content: center;
}

属性值:space-between

描述:项目位于各行之间留有空白的容器内。

.flex {
    flex-wrap: wrap;
    justify-content: space-between;
}

属性值:space-around

描述:项目位于各行之前、之间、之后都留有空白的容器内。

.flex {
    flex-wrap: wrap;
    justify-content: space-around;
}

转载于:https://www.cnblogs.com/f6056/p/10984395.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值