How can I move "3" to the end of the list using CSS?
See jsbin here
ul {
display: flex;
list-style: none;
margin: 0;
padding: 0;
}
li {
border: 1px solid black;
display: inline-block;
width: 50px;
height: 50px;
line-height: 50px;
text-align: center;
}
.end {
align-self: flex-end; /* this doesn't work; how can I move 3 to the end? */
}
<ul>
<li class="end">3</li>
<li>1</li>
<li>2</li>
</ul>
If you do want to align one item, or split a group on the main axis, use auto margins to do so; The align-items property sets all of the align-self values as a group. Use align-self on the flex child to set the value for an individual item.
To align one flex child to the right set it with margin-left: auto; From the flex spec: One use of auto margins in the main axis is to separate flex items into distinct "groups".
Use the order
property. In this case, order: 1
works because the other elements have their order set to 0
by default.
ul {
display: flex;
list-style: none;
margin: 0;
padding: 0;
}
li {
border: 1px solid black;
display: inline-block;
width: 50px;
height: 50px;
line-height: 50px;
text-align: center;
}
.end {
order: 1;
}
<ul>
<li class="end">3</li>
<li>1</li>
<li>2</li>
</ul>
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