flex-direction: column; is not working

给你一囗甜甜゛ 提交于 2020-01-03 09:07:52

问题


I have a ul tag with display: flex.

I need it ordered by column with flex-direction: column;, but it does not work.

css for the container

#nav li.four_columns ul.sub-menu {
  width: 600px;
  display: flex;
  -webkit-flex-direction: column;
  flex-direction: column;
  justify-content: flex-start;
  align-items: flex-start;
  flex-flow: wrap;
}

css for the child

#nav li.four_columns ul.sub-menu li {
  flex-basis: 25%;
  /* white-space: nowrap; */
  /* overflow: hidden; */
  /* text-overflow: ellipsis; */
  /* border-bottom: none; */
}

I appreciate the help.


回答1:


Here is the source of your problem: flex-flow: wrap

This is a shorthand property for flex-direction and/or flex-wrap.

The initial values of this property are row nowrap.

You have only declared the flex-wrap component: wrap.

This means that the flex-direction component remains the default value: row.

Hence, your flex items are aligning horizontally in a row that wraps.

As a solution, either specify both components:

flex-flow: column wrap

OR, since you already have flex-direction: column in the rule, remove flex-flow and use:

flex-wrap: wrap

Also important: If you want flex items to wrap in column-direction, you need to define a height on the container. Without a fixed height, the flex items don't know where to wrap and they'll stay in a single column, expanding the container as necessary.

Reference:

  • 5.3. Flex Direction and Wrap: the flex-flow shorthand


来源:https://stackoverflow.com/questions/38133315/flex-direction-column-is-not-working

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!