html - Issues combining display:flex, tables, and text-overflow: ellipsis -


i've got problem combining (top downwards) display:flex, flex items, table , cells containing text want truncate without affecting width of flex items, nor pushing table outside of flex item.

truncating text works fine if placed in inline-block inside flex item, when sit table/row/cell between two, table goes haywire.

i've looked @ setting ellipsis on text flex container, doesn't consider table elements, nor css tricks example. i've used these references set flexboxes.

here jsfiddle example , also:

/* flex layout */  .flex-space-between {    display: flex;    justify-content: space-between;  }  .flex-space-between > div {    width:100%;    flex: 1 1 auto;  }  .flex-with-gap { margin: -14px -7px; }  .flex-with-gap > div { margin: 14px 7px; }      /* colouring , other styles */  .flex-space-between > div {    box-sizing:border-box;    background-color:white;    border: solid 1px #999;    padding: 0.5em;min-width: 0;  }  body { font-family: sans-serif }    .truncate {    width:100%;    display: inline-block;    color:red;    white-space: nowrap;    overflow: hidden;    text-overflow: ellipsis;  }    .t1 {    width: 100%;    border-collapse:collapse;  }  .t1 td, .t1 th {    border:1px dotted blue;  }  .t1 th {    text-align:left;    font-weight:normal;  }  .t1 .number {    text-align:right;    font-size: 180%;    color:#66f;font-weight:bold;  }  .t1 .text {    max-width:80%;  }    .info { color: blue; font-style:italic;}
<div class='flex-space-between flex-with-gap'>    <div>      <div class='truncate'>mauris mauris ante, blandit et, ultrices a, suscipit eget, quam.</div>      <p class='info'>the div.truncate element above truncates fine.</p>    </div>        <div>    <div class='flex-space-between'>       <div class='truncate'>mauris mauris ante, blandit et, ultrices a, suscipit eget, quam.</div>      <div class='truncate'>mauris mauris ante, blandit et, ultrices a, suscipit eget, quam.</div>      </div>      <p class='info'>so above contained inside sub-flexboxes.</p>    </div>      <div></div>    <div></div>  </div>    <div class='flex-space-between flex-with-gap'>    <div></div>    <div>     <table class='t1'>    <tr>      <th class='text'>locations</th>      <td class='number'>123</td>    </tr>    <tr>      <th class='text'>divisions</th>      <td class='number'>123</td>    </tr>    <tr>      <th class='text'>business units business units business units</th>      <td class='number'>80</td>    </tr>    </table>    <p class='info'>now, i'm wanting place small table in flex items above (lists of text , numeric values) want text (e.g. business units) truncate if has to, , not wrap.</p>    </div>        <div>    <table class='t1'>    <tr>      <th class='text'>locations</th>      <td class='number'>123</td>    </tr>    <tr>      <th class='text'>divisions</th>      <td class='number'>123</td>    </tr>    <tr>      <th class='text'><div class='truncate'>business units business units business units</div></th>      <td class='number'>80</td>    </tr>    </table>    <p class='info'>but happens when trucating. "white-space: nowrap;" kicks in not "overflow: hidden;" nor "text-overflow: ellipsis;".</p>      <p class='info'>      think truncating text inside td/th problem not sure why.    </p>    </div>    <div style='opacity:0.9'></div>  </div>    <div class='flex-space-between flex-with-gap'>    <div>100%</div>  </div>    <div class='flex-space-between flex-with-gap'>    <div>33%</div><div>33%</div><div>33%</div>  </div>    <div class='flex-space-between flex-with-gap'>    <div>50%<br>multi-line line</div><div>50%</div>  </div>    <div class='flex-space-between flex-with-gap'>    <div>25%</div><div>25%</div><div>25%</div><div>25%</div>  </div>

you should switch other table layout algorithm: table-layout: fixed, 1 author (you) says , doesn't try adapt automagically content. if you're having problems widths set, try set them on first row.
max-width property on cells has no effect afaik. oops no, it's undefined behavior. changed width: 55% kind of fine here on guess page larger snippets here ymmv.

/* flex layout */  .flex-space-between {    display: flex;    justify-content: space-between;  }  .flex-space-between > div {    width:100%;    flex: 1 1 auto;  }  .flex-with-gap { margin: -14px -7px; }  .flex-with-gap > div { margin: 14px 7px; }      /* colouring , other styles */  .flex-space-between > div {    box-sizing:border-box;    background-color:white;    border: solid 1px #999;    padding: 0.5em;min-width: 0;  }  body { font-family: sans-serif }    .truncate {    width:100%;    display: inline-block;    color:red;    white-space: nowrap;    overflow: hidden;    text-overflow: ellipsis;  }    .t1 {    width: 100%;    border-collapse:collapse;    table-layout: fixed;  }  .t1 td, .t1 th {    border:1px dotted blue;  }  .t1 th {    text-align:left;    font-weight:normal;  }  .t1 .number {    text-align:right;    font-size: 180%;    color:#66f;font-weight:bold;  }  .t1 .text {    width: 55%;    background: yellow;  }    .info { color: blue; font-style:italic;}
<div class='flex-space-between flex-with-gap'>    <div>      <div class='truncate'>mauris mauris ante, blandit et, ultrices a, suscipit eget, quam.</div>      <p class='info'>the div.truncate element above truncates fine.</p>    </div>        <div>    <div class='flex-space-between'>       <div class='truncate'>mauris mauris ante, blandit et, ultrices a, suscipit eget, quam.</div>      <div class='truncate'>mauris mauris ante, blandit et, ultrices a, suscipit eget, quam.</div>      </div>      <p class='info'>so above contained inside sub-flexboxes.</p>    </div>      <div></div>    <div></div>  </div>    <div class='flex-space-between flex-with-gap'>    <div></div>    <div>     <table class='t1'>    <tr>      <th class='text'>locations</th>      <td class='number'>123</td>    </tr>    <tr>      <th class='text'>divisions</th>      <td class='number'>123</td>    </tr>    <tr>      <th class='text'>business units business units business units</th>      <td class='number'>80</td>    </tr>    </table>    <p class='info'>now, i'm wanting place small table in flex items above (lists of text , numeric values) want text (e.g. business units) truncate if has to, , not wrap.</p>    </div>        <div>    <table class='t1'>    <tr>      <th class='text'>locations</th>      <td class='number'>123</td>    </tr>    <tr>      <th class='text'>divisions</th>      <td class='number'>123</td>    </tr>    <tr>      <th class='text'><div class='truncate'>business units business units business units</div></th>      <td class='number'>80</td>    </tr>    </table>    <p class='info'>but happens when trucating. "white-space: nowrap;" kicks in not "overflow: hidden;" nor "text-overflow: ellipsis;".</p>      <p class='info'>      think truncating text inside td/th problem not sure why.    </p>    </div>    <div style='opacity:0.9'></div>  </div>    <div class='flex-space-between flex-with-gap'>    <div>100%</div>  </div>    <div class='flex-space-between flex-with-gap'>    <div>33%</div><div>33%</div><div>33%</div>  </div>    <div class='flex-space-between flex-with-gap'>    <div>50%<br>multi-line line</div><div>50%</div>  </div>    <div class='flex-space-between flex-with-gap'>    <div>25%</div><div>25%</div><div>25%</div><div>25%</div>  </div>


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -