css - How do I achieve the functionality shown in the image below? -


the need

i following below example flex box, not fit requirements

link.

case 1: left > right

case 2: left , right equal , fill space available

case 3: left , right lesser space available

case 4: left < right

in above cases, if left >> right, consumes entire width of box , 'right' not shown @ all.

as shown below.

the problem

question 1: how set minimum width 'left' , 'right' divs not out of view.

question 2: when left , right require more allocated space, both have occupy 50% width , truncated ellipsis.

html:

    <div id='parent5' class="parent">   <div class="left">left</div>   <div class="right">right</div> </div> <div id='parent5' class="parent">   <div class="left">lefkjasdkjsadkjhdkjsahdklksajdlksajsahdhkjsahdkjsahdkjsat</div>   <div class="right">rikjsadkjsahdkjsahdkjsahdkjsahdkjsahdkjsahdkjsahdksaght</div> </div> <div id='parent5' class="parent">   <div class="left">leaskjdkjsahdkjsahdkjsadkjhdsakjhdkjsahdkjsahdkjsahdkjhdkjsahdkjsaft</div>   <div class="right">right</div> </div> <div id='parent5' class="parent">   <div class="left">left</div>   <div class="right">rikjhsakjhdkjsahdkjsahdkjsahdkjsahdkjsahdkjsahdkjhsakjhdkjsahdjsadght</div> </div> <div id='parent5' class="parent">   <div class="left">lefsakdkjsahdkjsahdkjsahdkjsahdksadkjsadkjsadkjsahdsakhdkjsahdkjsahdkjsahdkjsahdkjsahdkjsahdkjsahdkjsakjsahdsat</div>   <div class="right">right</div> </div> 

css:

    .left {     padding: 1em;     background-color: #337ab7;     text-align: left; }  .right {     padding: 1em;     background-color: #5cb85c;     text-align: right;     }  .parent {     display: flex;     overflow: hidden;     margin: 1em 0;     color: #fff;     border: 1px solid #333;     align-items: center; }  #parent5 {     > div {         flex: 1;     } } 

you can adjust both flex-shrink , min-width result:

.left {    padding: 1em;    background-color: #337ab7;    text-align: left;  }  .right {    padding: 1em;    background-color: #5cb85c;    text-align: right;  }  .parent {    display: flex;    overflow: hidden;    margin: 1em 0;    color: #fff;    border: 1px solid #333;    align-items: center;  }  .parent div {    flex-basis: auto;    flex-grow: 1;    flex-shrink: 1;    min-width: 100px;     white-space: nowrap;    overflow: hidden;    text-overflow: ellipsis;  }
<div id='parent1' class="parent">    <div class="left">left</div>    <div class="right">right</div>  </div>  <div id='parent2' class="parent">    <div class="left">left long long long long long long long long long long long long long long long long</div>    <div class="right">right</div>  </div>  <div id='parent3' class="parent">    <div class="left">left</div>    <div class="right">right long long long long long long long long long long long long long long long long</div>  </div>  <div id='parent4' class="parent">    <div class="left">left long long long long long long long long long long long long long long long long</div>    <div class="right">right long long long long long long long long long long long long long long long long</div>  </div>  <div id='parent5' class="parent">    <div class="left">left</div>    <div class="right">right</div>  </div>


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -