css - flex 方向不工作

标签 css reactjs

我尽力了。但它不起作用。我想使用 flexbox 使我的元素内联,代码如下:

<div style={{
    flex: 1,
    flexDirection: 'column',
    justifyContent: 'center',
  }}>
    <div style={{width: 50, height: 50, backgroundColor: 'powderblue'}} />
    <div style={{width: 50, height: 50, backgroundColor: 'skyblue'}} />
    <div style={{width: 50, height: 50, backgroundColor: 'steelblue'}} />
  </div>

我所做的一切,它只按列呈现。有人能救我一命吗?

enter image description here

最佳答案

如果你想让它们内联,你应该使用row而不是column:

<div 
  style={{
    display: 'flex',
    flexFlow: "row nowrap",
    justifyContent: 'center',
  }}
>
    <div style={{width: 50, height: 50, backgroundColor: 'powderblue'}} />
    <div style={{width: 50, height: 50, backgroundColor: 'skyblue'}} />
    <div style={{width: 50, height: 50, backgroundColor: 'steelblue'}} />
</div>

flex 是子元素的属性。

关于css - flex 方向不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50435600/

相关文章:

javascript - 表格内的 asp.net 按钮未对齐

reactjs - 由于 useSelector 更新导致 useEffect 循环

javascript - 使用参数 ReactJS 从 API 请求中获取信息

html - 想要 Div 向右移动,

javascript - 如何在 MUI TextField 中设置样式?

javascript - react native 如何处理对象和数组?

javascript - React 对象在两个 View 中呈现不同的效果

javascript - 在 React 中如何考虑在类组件内部和类外部定义功能组件?

css - 在隐藏的溢出 div 标签中缩放和居中对齐 <img>

css - 覆盖 Bootstrap float 和 margin