3

怎么可能让 flexbox 容器的子项不拉伸水平溢出?这样您就可以使用 overflow-x 滚动或剪切右侧的内容。

在此处输入图像描述

我的实验以水平拉伸的项目结束,尽管它们具有固定的宽度。

4

1 回答 1

9

如果 flex-container 具有flex-wrap:no-wrap(默认),那么将其设置为overflow:auto;flex-items 为flex: 0 0 100%(或任何您想要的宽度而不是 100%)就足够了。

section{
  display:flex;
  width:100%;
  overflow:auto;
}

div{
  background-color:chartreuse;
  height:2rem;
  flex: 0 0 100%;
  box-sizing:border-box;
  border:5px solid red;
}
<section>
  <div></div>
  <div></div>
  <div></div>
  <div></div>  
</section>

于 2018-01-13T11:14:23.347 回答