In my research on SO, I encountered several posts related to this issue such as TD column width value not working with fixed table-layout and td widths, not working?. Despite trying the suggestions provided in those posts, assigning a width to td
does not result in the expected width. The problem is illustrated below:
div {
width: 400px;
padding: 5px;
border: 1px solid red;
}
table {
table-layout: fixed;
width: 100%;
border: 1px dotted green;
}
td {
word-break: break-all;
}
td:nth-of-type(1) {
width: 50px;
}
td:nth-of-type(2) {
width: 150px;
}
<div style="width: 400px;">
<table style="table-layout: fixed; width: 100%;">
<thead>
<tr>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td class="">
<a href="#">The_first_line</a>
</td>
<td class="">
<a href="#">The_second_but_a_long_line_with_so_many_characters</a>
</td>
<td class="">
<ul class="">
<li class=""><a href="#" rel="tag" title="" class="">The simple</a>
</li>
</ul>
</td>
<td>
<a href="#">last</a>
</td>
</tr>
</tbody>
</table>
</div>
The first td
should be 50px wide and the second should be 150px wide, however, this is not the case. Why is this happening?