Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to align items to right using flexbox?

I have a structure like so:

<footer>
    <ul>
        <li><a href="#">link 1</a></li>
        <li><a href="#">link 2</a></li>
        <li><a href="#">link 3</a></li>
    </ul>
</footer>

With floats, you could float: left the <li> elements and then float: right the <ul> to have the links in a row and the entire list at the "end" or the very right of the containing <footer>.

How would you accomplish this with flexbox, keeping the container <footer> element?

like image 618
user1087973 Avatar asked Aug 29 '17 05:08

user1087973


People also ask

How do I align text to the right in CSS Flexbox?

Now, alignment has become quite simple, since Flexbox allows us to align items and groups of items properly. In this snippet, we're interested in the case, when we need to align a flex item to the right. For that, you can use the CSS justify-content property with the “space-between” value on the flex container.


2 Answers

You can use justify-content: flex-end

Below is necessary CSS:

footer ul {
  justify-content: flex-end;
  display: flex;
}

footer ul {
  justify-content: flex-end;
  list-style: none;
  display: flex;
}
footer ul li {
  padding: 0 10px;
}
<footer>
  <ul>
    <li><a href="#">link 1</a></li>
    <li><a href="#">link 2</a></li>
    <li><a href="#">link 3</a></li>
  </ul>
</footer>
like image 88
Mohammad Usman Avatar answered Oct 22 '22 01:10

Mohammad Usman


Check the code below. You can use justify-content: flex-end; so that the flex content will align to the right

footer ul {
  list-style: none;
  display: flex;
  justify-content: flex-end;
}
<footer>
  <ul>
    <li><a href="#">link 1</a></li>
    <li><a href="#">link 2</a></li>
    <li><a href="#">link 3</a></li>
  </ul>
</footer>
like image 29
bellabelle Avatar answered Oct 22 '22 03:10

bellabelle