-1

I have three flex items in my flex box. I want the first two centered and the last one to align all the way to the right along the main axis.

really basic overview:

<div class="flex flex-center">
  <div>flex item 1</div>
  <div>flex item 2</div>
  <div style="margin-left: auto;">flex item 3</div>
</div>

My CSS for the flex class is:

.flex {
  display: flex;

  &.flex-center {
    align-items: center;
  }
}

What happens when I use a margin-left: auto; is it pushes the first two flex items to the flex start of the main axis. I want the first two flex items centered, and the third item to align all the way to the right (end) of the main axis.

randombits
  • 47,058
  • 76
  • 251
  • 433

1 Answers1

0

Sounds like you just need to do a little math and use the last-child selector. Take a look at my pen here and tell me if this is what you needed.

EDIT: I now think the best way to do this would be with some hidden spacer elements and the flex-grow property. Example here.

jpegzilla
  • 80
  • 2
  • 10