Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Move one element to the end of a list with flexbox [duplicate]

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>
like image 215
mpen Avatar asked Dec 30 '16 02:12

mpen


People also ask

How do I align one item in flexbox?

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.

How do I align one item to the right in CSS?

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".


1 Answers

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>
like image 67
Jon Uleis Avatar answered Sep 21 '22 06:09

Jon Uleis