I have HTML table. I want to auto set the width of table columns , which changes as per the content. For example in below image you can see ID column content has to come in a single line, but even though width is set to auto , its not working here. Am i missing out on something? Please find my code below: CSS:
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
width: auto !important;
overflow: hidden;
}
tr:nth-child(even) {
background-color: #dddddd;
}
</style>
html table:
<table>
<thead>
<tr>
<th></th>
<th>ID</th>
<th>Company Name</th>
<th>Address</th>
</tr>
</thead>
<tbody>
@foreach (Models.UTP utpResult in lstUtpResult.utp)
{
<tr>
<td>
<input value="1" id="type_radio_1" name="type_radio" type="radio" />
</td>
<td>@utpResult.id</td>
<td>@utpResult.companyName</td>
<td>@utpResult.address.street.Line1,
@utpResult.address.city,
@utpResult.address.zip.code,
@utpResult.address.country.name
</td>
</tr>
}
</tbody>
</table>
