I am trying to make the wrapper div scrollable when elements inside exceed the width of the wrapper. I applied overflow: auto
but it is not making it scrollable. What am I missing and how can I fix it? Thanks in advance.
.wrapper {
display: flex;
flex-direction: row;
justify-content: left;
column-gap: 10px;
width: 100%;
height: 30vh;
overflow: auto;
background-color: gold;
}
.container {
width: 100px;
height: 100%;
background-color: darkcyan;
}
<div class="wrapper">
<div class="container">
</div>
<div class="container">
</div>
<div class="container">
</div>
<div class="container">
</div>
<div class="container">
</div>
<div class="container">
</div>
<div class="container">
</div>
</div>
2
Answers
flex
makes its children shrink and growBy default, a flex item (i.e. a child element inside a flex container) will grow or shrink flexibly. Thus, the naming "flexbox."
In your snippet, even though you specified
width: 100px;
to.container
elements, you haven’t specified itsflex-grow
orflex-shrink
values.Try giving
.container
a specificflex
value that stops them from growing/shrinking.You need set
flex-grow
andflex-shrink
to 0 for set shrink factor of container. Try replacewidth: 100px
withflex: 0 0 100px
.