Set the width of a column using table td:nth-of-type()

Let's assume that you are working with the following table:

html
<div className = 'Table'>
    <table>
        <thead>
            <tr>
                <th>Today</th>
                <th>Tomorrow</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>Code</td>
                <td>Read</td>
            </tr>
        </tbody>
    </table>
</div>

Let's assume that you want to set the width of the first column to 200px:

CSS
.Table td:nth-of-type(1),
.Table th:nth-of-type(1){
    width: 200px;
}

Important: you should modify both td and th width. Otherwise, the width will remain constant.

Hi, I'm Erik, an engineer from Barcelona. If you like the post or have any comments, say hi.