If you have full control over the markup, consider using div
and applying display: flex;
instead of using a table
. Using JavaScript might be unnecessary in this case. (Please note the IE11 limitation)
I've provided a simple example to help you start, although I'm not entirely sure about the desired behavior for td2
& td4
.
However, if you wish to set a maximum width for those elements, you can refer to this solution:
#td2 {
flex-grow: 0;
flex-shrink: 0;
flex-basis: 200px;
}
Additionally, use the following for #td1
:
#td1 {
flex-grow: 1;
}
This will allow #td1
to fill up the space automatically while keeping 200px for #td2
.
In general, it is recommended to use classes instead of IDs when working with CSS.
Check out this Codepen link
Best of luck implementing these changes!