How to use display:flex in CSS to create a mix of fixed with and dynamic proportional width columns? -


i'm kind of new latecomers display:flex thing in css. want create table 9 column, want column has fixed width, , column has dynamic proportional width against other dynamic proportional width column. content 1 line, , overflow content truncated ellipsis. now, used javascript plugin that. after accidentally stumbles display:flex, i'm thinking i'm going change this, because using javascript heavy if table huge.

but i'm confused on how that. read need have container (<tr>?) display:flex, column (<td>?) getting order value.

what need this: col 1: 100px col 2: 100px col 3: 200px col 4: 15% remaining dynamic length col 5: 20% remaining dynamic length col 6: 35% remaining dynamic length col 7: 40% remaining dynamic length col 8: 100px col 9: 250px

and code simple table:

<table style="width:100%">     <tr>         <td><input type="checkbox" onclick="selectall()"</input></td>         <td>no</td>         <td>id</td>         <td>name</td>         <td>address</td>         <td>description</td>         <td>notes</td>         <td>score</td>         <td>option button</td>     </tr>     <tr>         <td><input type="checkbox" id="cr-10234"></td>         <td>1</td>         <td>cr-10234</td>         <td>maxwell, harry</td>         <td>harrison, ohio</td>         <td>it engineering 3 years experience in web programming</td>         <td>currently stays in san fransisco. need 3 days in advance book schedule.</td>         <td>89</td>         <td>              <input type="button" onclick="edit('cr-10234')">edit</input>              <input type="button" onclick="delete('cr-10234')">delete</input>         </td>     </tr> </table> 

how can add display flex thing? need add style attribute / class attribute each <td> each <tr>?

flexbox isn't intended use on tables. you'd better off rebuilding whiole thing divs if need use flexbox.

also, flexbox doesn't % of remaining width automatically

you use calc on existing table. no need flexbox @ all.

* {    box-sizing: border-box;  }    table {    width: 100%;    margin: 10px 0;    border:1px solid grey;  }    td:nth-child(1),   td:nth-child(2),   td:nth-child(8)  {  width: 100px;   /* total 300px */  background: plum;  }    td:nth-child(3) {  width: 200px;     background: #c0ffee;  }    td:nth-child(9) {  width: 250px;    }    /* total fixed widths = 750px */    td:nth-child(4) {  width: calc((100% - 750px) * .15);      background: #bada55;  }    td:nth-child(5) {  width: calc((100% - 750px) * .2);    }    td:nth-child(6) {  width: calc((100% - 750px) * .35);    }    td:nth-child(7) {  width: calc((100% - 750px) * .45);    }
<table>      <tr>          <td><input type="checkbox" onclick="selectall()"</input></td>          <td>no</td>          <td>id</td>          <td>name</td>          <td>address</td>          <td>description</td>          <td>notes</td>          <td>score</td>          <td>option button</td>      </tr>  </table>

codepen demo


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -