css教程网 css教程网365css.cn
公告为您打开互联网世界的窗户关于本站
首页/属性速查/布局与定位

flex-direction

决定 Flex 主轴方向,也就决定了 justify 与 align 各自作用在哪根轴上。

语法
flex-direction: row | row-reverse | column | column-reverse
常用值
row / row-reverse / column / column-reverse
初始值
row
继承
否

运行效果

示例改成别的值试试,差异一眼能看出来
查看代码
HTML
<div class="fd"><i>1</i><i>2</i><i>3</i></div>
CSS
.fd { display: flex; flex-direction: column; gap: 5px; width: 90px; }
.fd i { height: 22px; border-radius: 5px; background: #2b57ff; color: #fff; display: grid; place-items: center; font: 600 10px/1 ui-monospace, monospace; font-style: normal; opacity: .9; }

使用要点

  • 改成 column 后,justify-content 管纵向,align-items 管横向,两个属性会「换轴」。