I'd like to use flex-direction:column
for a specific layout.
I usually use standard flex-direction:row
, so I've got some problems using column
. I don't know too much how to control it and didn't find anything useful on google.
I've got a regular UL
list and what I want is this:
1 3 5 7
2 4 6
What I currently get is this:
1
2
3
4
5
6
7
My current simplified code is this:
.ul{
display: flex;
flex-direction: column;
li{
width: 25%;
}
}
Making things wrap If you want to cause them to wrap once they become too wide you must add the flex-wrap property with a value of wrap , or use the shorthand flex-flow with values of row wrap or column wrap . Items will then wrap in the container.
The flex columns can be aligned left or right by using the align-content property in the flex container class. The align-content property changes the behavior of the flex-wrap property. It aligns flex lines. It is used to specify the alignment between the lines inside a flexible container.
The flex container's main-axis is the same as the block-axis. The main-start and main-end points are the same as the before and after points of the writing-mode. column-reverse. Behaves the same as column but the main-start and main-end are opposite to the content direction.
Apply total height
on ul
and make it wrap
.
Then apply flex-basis
on ul li
(which is height because we've applied flex-direction: column
) to 50%. Like:
ul {
display: flex;
flex-wrap: wrap;
flex-direction: column;
height: 100px;
}
ul li {
flex-basis: 50%; /* which in this case will be '50px' */
}
Have a look at the snippet below:
ul {
list-style: none;
margin: 0;
padding: 0;
display: flex;
flex-wrap: wrap;
flex-direction: column;
height: 100px;
}
ul li {
flex-basis: 50%;
}
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
</ul>
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With