css justify-content 用于设置或检索弹性盒子元素在主轴(横轴)方向上的对齐方式,对齐方式有:位于容器的开头、位于容器的结尾、位于容器的中心、均匀分布等等。

css justify-content属性怎么用?
justify-content 用于设置或检索弹性盒子元素在主轴(横轴)方向上的对齐方式。可以使用 align-content 属性对齐交叉轴上的各项(垂直)。
语法:
立即学习“前端免费学习笔记(深入)”;
justify-content: flex-start|flex-end|center|space-between|space-around|initial|inherit;
属性值:
● flex-start:默认值。项目位于容器的开头。

● flex-end:项目位于容器的结尾。

● center:项目位于容器的中心。

● space-between:项目位于各行之间留有空白的容器内,即均匀分布在线上; 第一项是在起始行,最后一项是在结束行。

● space-around:项目位于各行之前、之间、之后都留有空白的容器内。

● initial:设置该属性为它的默认值。
● inherit:从父元素继承该属性。
css justify-content属性 示例
.flex-container { padding: 0; margin: 0; list-style: none; display: flex;}.flex-start { justify-content: flex-start; }.flex-end { justify-content: flex-end; } .flex-end li { background: gold;}.center { justify-content: center; } .center li { background: deepskyblue;}.space-between { justify-content: space-between; } .space-between li { background: lightgreen;}.space-around { justify-content: space-around; }.space-around li { background: hotpink; }.space-evenly { justify-content: space-evenly; }.space-evenly li { background: #bada55; }.flex-item { background: tomato; padding: 5px; width: 60px; height: 50px; margin: 5px; line-height: 50px; color: white; font-weight: bold; font-size: 2em; text-align: center;}- 1
- 2
- 3
- 4
- 5
- 1
- 2
- 3
- 4
- 5
- 1
- 2
- 3
- 4
- 5
- 1
- 2
- 3
- 4
- 5
- 1
- 2
- 3
- 4
- 5
- 1
- 2
- 3
- 4
- 5
效果图:

说明:
红色列表是justify-content属性设置为 flex-start
黄色是justify-content属性设置为 flex-end
蓝色是justify-content属性设置为 center
绿色是justify-content属性设置为 space-between
粉红色是justify-content属性设置为 space-around
浅绿色是justify-content属性设置为 space-evenly
以上就是css justify-content属性怎么用的详细内容,更多请关注创想鸟其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/1614665.html
微信扫一扫
支付宝扫一扫