2

I'm very new to CSS, and I'm struggling on positioning a flex item (DownloadButton) the way I want it too.

I want to position a flex item a certain way, but my googling skills are failing me.

The current state looks like this:

Icon DownloadButton DeleteButton

What I want is this:

Icon DownloadButton DeleteButton

I thought I could use align-items, but that's for the cross axis. Rather than even spacing, like the normal flex behavior, I want my DownloadButton hugging the DeleteButton at the end. However, my Googling skills have failed me. Help would be greatly appreciated, thanks guys!

Michael Benjamin
  • 346,931
  • 104
  • 581
  • 701
RFang
  • 137
  • 1
  • 8

2 Answers2

3

I would align the items to the end (for preference) and then adjust the first one.

As pointed out in the comments the end alignment is not necessary as the effect is caused by the margin adjustment.

.parent {
  width: 80%;
  margin: 1em auto;
  border: 1px solid grey;
  display: flex;
  justify-content: flex-end;
  padding: .5em;
}
button:first-child {
  margin-right: auto;
}
<div class="parent">
  <button>Icon</button>
  <button>Download</button>
  <button>Delete</button>
</div>
Paulie_D
  • 107,962
  • 13
  • 142
  • 161
0

Add these styles to the container:

#flex-container { /*Select Your Flex Container*/
display: flex;
flex-direction: row;
justify-content: space-between;
}

Add these styles for the flexible items:

.flexible-items { /*Select The Children Of The Flex Container*/
flex-grow: 0; /*This Is Default*/
}
#Icon {
flex-grow: 1;
}

If you want some space between the other two flexible items, you can achieve this by multiple methods, 1 being to add some margin and padding styles for their sides.

Zed Strong
  • 11
  • 4