0

I have been slamming my head into this one for awhile and I think I actually might have run into something that isn't possible.

I have a navigation menu that has some extreme differences in length of content. I want to space that content perfectly even no matter where the line break occurs, depending upon the width of the parent container. I'm using flexbox for this, but I can't seem to get exactly what I'm looking for.

Here is my markup:

.nav-holder {
  width: 500px;
  border:1px solid blue;
  padding: 1px;
}
.nav{
  display: flex;
  flex-wrap: nowrap;
  justify-content:space-between;
  width: 100%;
}
.nav-item {
  border: 1px solid red;
}
<div class="nav-holder">
  <div class="nav">
    <div class="nav-item">Home</div>
    <div class="nav-item">Manufacturing Services</div>
    <div class="nav-item">Specialized Manufacturing Services</div>
    <div class="nav-item">Media &amp; News</div>
    <div class="nav-item">Contact</div>
  </div>
</div>

Here is what is happening:

What is happening

Here is what I would like to happen:

What I would like to happen

I achieved that by manually setting the width of the two long items to exact pixels. That is not acceptable considering that the content may change.

I essentially want the div to get the EXACT width of actual content if it is too long and has to break to the next line instead of filling out the rest of that space with nothing.

Cory Dymond
  • 251
  • 3
  • 2
  • Does this answer your question? [Better way to set distance between flexbox items](https://stackoverflow.com/questions/20626685/better-way-to-set-distance-between-flexbox-items) – Libra Jan 06 '20 at 22:18
  • You are right, this is impossible – Temani Afif Jan 06 '20 at 22:23
  • @Laif No, I need the flex items to size down depending upon the exact width of the text content. I have no problem setting gutters on my own. – Cory Dymond Jan 07 '20 at 21:55
  • @TemaniAfif I figured as much. It doesn't seem like a problem that can be solved here. I managed to get it working by explicitly setting `
    `'s for each word where I knew they would be needed. This allows the browser to calculate the exact width, which works for my purposes.
    – Cory Dymond Jan 07 '20 at 21:57

0 Answers0