什么导致我的弹性盒子容器在使用overflow-x: scroll后仍然无法水平滚动?

huangapple go评论66阅读模式
英文:

What's causing my flexbox container to not scroll horizontally despite using overflow-x: scroll?

问题

I have no idea what I'm doing wrong here and this was supposed to work. I'm not able to set the desired width for the child elements and make the parent overflow with a horizontal scroll. After a specific width the width won't increase and seems to get stuck at that point.

This is the html -

<div className="container">
    <div className="item">item 1</div>
    <div className="item">item 2</div>
    <div className="item">item 2</div>
</div>

And the css -

.container {
  display: flex;
  overflow-x: scroll;
}

.item {
  height: 5rem;
  width: 25rem;
  border: 2px solid black;
}

codesandbox link: https://codesandbox.io/s/pedantic-darkness-yx1wht

英文:

I have no idea what I'm doing wrong here and this was supposed to work. I'm not able to set the desired width for the child elements and make the parent overflow with a horizontal scroll. After a specific width the width won't increase and seems to get stuck at that point.

This is the html -

 &lt;div className=&quot;container&quot;&gt;
        &lt;div className=&quot;item&quot;&gt;item 1&lt;/div&gt;
        &lt;div className=&quot;item&quot;&gt;item 2&lt;/div&gt;
        &lt;div className=&quot;item&quot;&gt;item 2&lt;/div&gt;
 &lt;/div&gt;

And the css -

.container {
  display: flex;
  overflow-x: scroll;
}

.item {
  height: 5rem;
  width: 25rem;
  border: 2px solid black;
}

codesandbox link : https://codesandbox.io/s/pedantic-darkness-yx1wht

答案1

得分: 1

以下是翻译好的部分:

解决方案之一是使用min-width而不仅仅是width,如果需要响应式变化,您可以继续使用min-width进行操作。

演示

英文:

One of the solutions to this is adding min-width instead of just width and if you need it in responsive to change you can continue manipulating with min-width

Demo

huangapple
  • 本文由 发表于 2023年5月25日 20:29:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/76332282.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定