I have a table with one TR and 2 TD\'s. I want the first TD to adjust width automatically depending on its content, and the second TD to use up the remainder of the width.>
You can give the first td
a small width, e.g. 1px
, with white-space: nowrap;
table {
width: 100%;
border-collapse: collapse;
}
td {
border: 1px solid red;
}
td:first-child {
width: 1px;
white-space: nowrap;
}
short content
long content
Or, give the last td
a large width, e.g. 100%
.
table {
width: 100%;
border-collapse: collapse;
}
td {
border: 1px solid red;
}
td:first-child {
white-space: nowrap;
}
td:last-child {
width: 100%;
}
short content
long content