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

CSS wrap divs text content into one line and then make a word-wrap on that line

I have this:

<html>
  <div style="width: 300px; border: solid 1px gray">
    <div style="width: 100%; display: flex; justify-content: center;           min-height: 36px">  
        <div>This is a test</div>
        <div>This is another test</div>
        <div>This is a just another test</div>
        <div>This is the final test</div>
    </div>
  </div>
</html>

Which is not the desired result, so I added some styling and finally I got all in one line. Right now I’m getting these divs contents outside of the containter, but I need to make them a single line and wrap that line, something like:

This is a test This is another test This is
a just another test This is the final test
<html>
  <div style="width: 300px; border: solid 1px gray">
    <div style="width: 100%; display: flex; justify-content: center;           min-height: 36px">  
      <div style="white-space: nowrap; display: flex">
        <div>This is a test</div>
        <div>This is another test</div>
        <div>This is a just another test</div>
        <div>This is the final test</div>
      </div>
    </div>
  </div>
</html>

What am I missing?

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 :

You don’t need flexbox for this:

.box {
  width: 100%;
  min-height: 36px;
}

.box div {
  display: inline
}
<div style="width: 300px; border: solid 1px gray">
  <div class="box">
    <div>This is a test</div>
    <div>This is another test</div>
    <div>This is a just another test</div>
    <div>This is the final test</div>
  </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