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

How to set the div width properly insedi a flexbox?

I have this code

<div style="display:flex; justify-content:space-between; width:100%">
    <div id="this">
       <h3>Title</h3>
    </div>
    <div>
      <input type="radio">
      <input type="radio">
      <input type="radio">
   </div>
   <div>
      <p>Text</p>
   </div>
</div>

I want to set the #this div width so that it is exactly the same size as the space-between attribute creates for it without push away the other elements. (The first puple section).

Basically what i want is to handle if the text is to long, by hidding it’s overflow, but first I need to set it’s width, and I want to show as much as its possible without pushing away other elements

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

If there’s another way to handle long text that’s fine too, just make it work like how I want.

enter image description here

I try to set the div width, max-width but can’t figured out, each way the other elements are pushed away

>Solution :

Use Flex:1; to set width to maximum available space between elements

You can see the detailed document about flex here

#this,#another{
  border:1px solid;
  flex:1;
}
<div style="display:flex; justify-content:space-between; width:100%">
    <div id="this">
       <h3>Title</h3>
    </div>
    <div>
      <input type="radio">
      <input type="radio">
      <input type="radio">
   </div>
   <div id ="another">
      <p>Text</p>
   </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