主軸

Flexbox 中的主軸由 flex-direction 屬性定義的行進方向決定。flex-direction 有四種可能的值。它們是:

  • row
  • row-reverse
  • column
  • column-reverse

如果選擇 rowrow-reverse,則主軸將沿著內聯方向的行進行。

In this image the flex-direction is row which forms the main axis

選擇 columncolumn-reverse,則主軸將沿著頁面的自上而下方向進行。

Three flex items taking up the full width of the container, displayed one below the other in code order. Flex-direction is set to column. The main axis is vertical i.e., from top to bottom

在主軸上,您可以透過在 flex 項上設定 flex 屬性,將可用空間分配給 flex 項本身來控制其大小。或者,您可以使用 justify-content 屬性來控制項之間的空間以及項周圍的空間。