I have a container with many items inside.
I would like to display them alternatively on a single row (with eventually an horizontal scrollbar on container) or wrapped in multiple rows.
I thought to use Flexbox Layout module. Two examples are visible in this here:
.single-line {
border: solid 1px blue;
width: 50%;
overflow-x: scroll;
}
.wrap-line {
border: solid 1px green;
width: 50%;
}
ul {
list-style: none;
margin: 0;
padding: 0;
display: flex;
flex-direction: row;
justify-content: space-around;
}
.single-line ul {
flex-wrap: nowrap;
}
.wrap-line ul {
flex-wrap: wrap;
}
li {
display: block;
width: 40px;
height: 40px;
background: gray;
text-align: center;
border: solid 1px red;
line-height: 40px;
}
<div class="single-line">
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
<li>8</li>
<li>9</li>
</ul>
</div>
<br>
<div class="wrap-line">
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
<li>8</li>
<li>9</li>
</ul>
</div>
The most important code is the following:
ul {
display: flex;
flex-direction: row;
justify-content: space-around;
}
.single-line ul {
flex-wrap: nowrap;
}
.wrap-line ul {
flex-wrap: wrap;
}
It is close to what I would like but there are some issues:
First example shrinks inner blocks, so the container is not scrollable. How to solve that?
In the second example, how do I add vertical separation between lines but not at the edges of the container? I thought about
margin-bottom
on eachLI
but this is not the right solution (and I can't set a fixed height for container)