Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Using flex to stop elements from overlapping on the same line

I have mocked up my issue whereby I have a dropdown that includes "added" options (in black boxes) like so: can I use flex to stop an option splitting over two lines and them bunching up all of the time? I could have any number of options depending on the users input.

.dropdown {
  top: 100%;
  max-width: 150px;
  white-space: normal;
  padding: 0.5rem 0rem;
  margin: 0.125rem 0rem 0rem;
  border: 1px solid grey;
}

.options-wrapper {
  margin-left: 16px;
  margin-bottom: 8px;
}

.option {
  padding: 8px;
  background-color: black;
  color: white;
  min-width: 120px;
}
<div class="dropdown">
  <div class="options-wrapper">
    <span class="option">Accepted</span>
    <span class="option">In progress</span>
  </div>
</div>

They should behave like so:
enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Yes. You can use flex to solve this.

All changes were made in .options-wrapper using flex. Also one addition to .option to add margin. I also commented out the max-width to mimic your image.

.dropdown {
  top: 100%;
  /* max-width: 150px; */
  white-space: normal;
  padding: 0.5rem 0rem;
  margin: 0.125rem 0rem 0rem;
  border: 1px solid grey;
}

.options-wrapper {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
}

.option {
  padding: 8px;
  background-color: black;
  color: white;
  min-width: 120px;
  margin: .5rem;
}
<div class="dropdown">
  <div class="options-wrapper">
    <span class="option">Accepted</span>
    <span class="option">In progress</span>
  </div>
</div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading