How to make a td element fit content?
Hi guys, I have a table with 2 columns, the first column I want the width fit content, and the second one take the rest width. How can I archive this?
10 Replies
Assuming that you want the first column contents to be on a single line you could apply
white-space: nowrap; to that one and then width:100% to the second column
you might want to use grid for the table, as the grid layout is a lot more sensible
Sry for late reply. It works as I expect. Thanks
Do you mean using elements like <div> and arranging them with CSS Grid?
no, i meant grid
Can you give me an example? 😅
it's just css grid
grid-template-columns: max-content auto should do itOh, it seems to work well in my case. Thanks
yup, but chris' way is better in some aspects, as you don't have to change the display type of anything, which can have weird effects
Noted. Thanks for your advice
you're welcome