[html] Table with table-layout: fixed; and how to make one column wider

So I have a table with this style:

table-layout: fixed;

Which makes all columns to be of the same width. I would like to have one column (the first one) to be wider and then rest of the columns to occupy the remaining width of the table with equal widths.

How to achieve that?

_x000D_
_x000D_
table {_x000D_
  border-collapse: collapse;_x000D_
  width: 100%;_x000D_
  border: 1px solid black;_x000D_
  background: #ddd;_x000D_
  table-layout: fixed;_x000D_
}_x000D_
_x000D_
table th, table td {_x000D_
  border: 1px solid #000;_x000D_
}_x000D_
_x000D_
table td.wideRow, table th.wideRow {_x000D_
  width: 300px;_x000D_
}
_x000D_
<table class="CalendarReservationsBodyTable">_x000D_
  <thead>_x000D_
    <tr>_x000D_
      <th colspan="97">Rezervovane auta</th>_x000D_
    </tr>_x000D_
    <tr>_x000D_
      <th class="corner wideRow">Auto</th>_x000D_
      <th class="odd" colspan="4">0</th>_x000D_
      <th class="" colspan="4">1</th>_x000D_
      <th class="odd" colspan="4">2</th>_x000D_
      <th class="" colspan="4">3</th>_x000D_
      <th class="odd" colspan="4">4</th>_x000D_
      <th class="" colspan="4">5</th>_x000D_
      <th class="odd" colspan="4">6</th>_x000D_
      <th class="" colspan="4">7</th>_x000D_
      <th class="odd" colspan="4">8</th>_x000D_
      <th class="" colspan="4">9</th>_x000D_
      <th class="odd" colspan="4">10</th>_x000D_
      <th class="" colspan="4">11</th>_x000D_
      <th class="odd" colspan="4">12</th>_x000D_
      <th class="" colspan="4">13</th>_x000D_
      <th class="odd" colspan="4">14</th>_x000D_
      <th class="" colspan="4">15</th>_x000D_
      <th class="odd" colspan="4">16</th>_x000D_
      <th class="" colspan="4">17</th>_x000D_
      <th class="odd" colspan="4">18</th>_x000D_
      <th class="" colspan="4">19</th>_x000D_
      <th class="odd" colspan="4">20</th>_x000D_
      <th class="" colspan="4">21</th>_x000D_
      <th class="odd" colspan="4">22</th>_x000D_
      <th class="" colspan="4">23</th>_x000D_
    </tr>_x000D_
  </thead>_x000D_
  <tbody>_x000D_
    <tr>_x000D_
      <td class="alignRight wideRow">KE-260 FC - Octavia combi</td>_x000D_
      <td class=" borderLeft"></td>_x000D_
      <td class="odd"></td>_x000D_
      <td class=""></td>_x000D_
      <td class="odd"></td>_x000D_
      <td class=" borderLeft"></td>_x000D_
      <td class="odd"></td>_x000D_
      <td class=""></td>_x000D_
      <td class="odd"></td>_x000D_
      <td class=" borderLeft"></td>_x000D_
      <td class="odd"></td>_x000D_
      <td class=""></td>_x000D_
      <td class="odd"></td>_x000D_
      <td class=" borderLeft"></td>_x000D_
      <td class="odd"></td>_x000D_
      <td class=""></td>_x000D_
      <td class="odd"></td>_x000D_
      <td class=" borderLeft"></td>_x000D_
      <td class="odd"></td>_x000D_
      <td class=""></td>_x000D_
      <td class="odd"></td>_x000D_
      <td class=" borderLeft"></td>_x000D_
      <td class="odd"></td>_x000D_
      <td class=""></td>_x000D_
      <td class="odd"></td>_x000D_
      <td class=" borderLeft"></td>_x000D_
      <td class="odd"></td>_x000D_
      <td class=""></td>_x000D_
      <td class="odd"></td>_x000D_
      <td class=" borderLeft"></td>_x000D_
      <td class="odd"></td>_x000D_
      <td class=""></td>_x000D_
      <td class="odd"></td>_x000D_
      <td colspan="16" class="highlighted borderLeft" title="Richard Knop">_x000D_
        Richard Knop_x000D_
      </td>_x000D_
      <td class=" borderLeft"></td>_x000D_
      <td class="odd"></td>_x000D_
      <td class=""></td>_x000D_
      <td class="odd"></td>_x000D_
      <td class=" borderLeft"></td>_x000D_
      <td class="odd"></td>_x000D_
      <td class=""></td>_x000D_
      <td class="odd"></td>_x000D_
      <td class=" borderLeft"></td>_x000D_
      <td colspan="14" class="highlighted" title="Richard Knop">_x000D_
        Richard Knop_x000D_
      </td>_x000D_
      <td class="odd"></td>_x000D_
      <td class=" borderLeft"></td>_x000D_
      <td class="odd"></td>_x000D_
      <td class=""></td>_x000D_
      <td class="odd"></td>_x000D_
      <td class=" borderLeft"></td>_x000D_
      <td class="odd"></td>_x000D_
      <td class=""></td>_x000D_
      <td class="odd"></td>_x000D_
      <td class=" borderLeft"></td>_x000D_
      <td class="odd"></td>_x000D_
      <td class=""></td>_x000D_
      <td class="odd"></td>_x000D_
      <td class=" borderLeft"></td>_x000D_
      <td class="odd"></td>_x000D_
      <td class=""></td>_x000D_
      <td class="odd"></td>_x000D_
      <td class=" borderLeft"></td>_x000D_
      <td class="odd"></td>_x000D_
      <td class=""></td>_x000D_
      <td class="odd"></td>_x000D_
      <td class=" borderLeft"></td>_x000D_
      <td class="odd"></td>_x000D_
      <td class=""></td>_x000D_
      <td class="odd"></td>_x000D_
    </tr>_x000D_
  </tbody>_x000D_
</table>
_x000D_
_x000D_
_x000D_

jsfiddle: http://jsfiddle.net/6p9K3/

Notice the first column, I want it to be 300px wide.

This question is related to html css xhtml

The answer is


The important thing of table-layout: fixed is that the column widths are determined by the first row of the table.

So

if your table structure is as follow (standard table structure)

<table>
  <thead>
      <tr>
          <th> First column </th>
          <th> Second column </th>
          <th> Third column </th>        
      </tr>
  </thead>

   <tbody>
      <tr>
          <td> First column </td>
          <td> Second column </td>
          <td> Third column </td>        
      </tr>
  </tbody>

if you would like to give a width to second column then

<style> 
    table{
        table-layout:fixed;
        width: 100%;
    }

    table tr th:nth-child(2){
       width: 60%;
     }

</style>

Please look that we style the th not the td.


Are you creating a very large table (hundreds of rows and columns)? If so, table-layout: fixed; is a good idea, as the browser only needs to read the first row in order to compute and render the entire table, so it loads faster.

But if not, I would suggest dumping table-layout: fixed; and changing your css as follows:

table th, table td{
border: 1px solid #000;
width:20px;  //or something similar   
}

table td.wideRow, table th.wideRow{
width: 300px;
}

http://jsfiddle.net/6p9K3/1/


What you could do is something like this (pseudocode):

<container table>
  <tr>
    <td>
      <"300px" table>
    <td>
      <fixed layout table>

Basically, split up the table into two tables and have it contained by another table.


Examples related to html

Embed ruby within URL : Middleman Blog Please help me convert this script to a simple image slider Generating a list of pages (not posts) without the index file Why there is this "clear" class before footer? Is it possible to change the content HTML5 alert messages? Getting all files in directory with ajax DevTools failed to load SourceMap: Could not load content for chrome-extension How to set width of mat-table column in angular? How to open a link in new tab using angular? ERROR Error: Uncaught (in promise), Cannot match any routes. URL Segment

Examples related to css

need to add a class to an element Using Lato fonts in my css (@font-face) Please help me convert this script to a simple image slider Why there is this "clear" class before footer? How to set width of mat-table column in angular? Center content vertically on Vuetify bootstrap 4 file input doesn't show the file name Bootstrap 4: responsive sidebar menu to top navbar Stylesheet not loaded because of MIME-type Force flex item to span full row width

Examples related to xhtml

How to refresh table contents in div using jquery/ajax Uses for the '&quot;' entity in HTML The entity name must immediately follow the '&' in the entity reference Can I save input from form to .txt in HTML, using JAVASCRIPT/jQuery, and then use it? How to vertically align a html radio button to it's label? Image height and width not working? Removing border from table cells Enable & Disable a Div and its elements in Javascript how to remove the bold from a headline? How to make div occupy remaining height?