For the past 3 days, I've been struggling to implement a table design that our UX designer is requesting.
The challenge is to create a table with N columns, where the first N-1 columns align to the left of the screen and the last column aligns to the right. Each column should adjust its width based on the largest element in its rows, with a consistent 24px spacing between columns. As the screen size decreases and white space becomes limited, text overflow should be displayed as ellipses while ensuring the table does not overflow off the screen.
I have tried various solutions found online and even experimented with chatbot suggestions, but none have fully met the requirements.
When using table layout fixed, the text does not expand to fill available white space; table layout auto expands text but fails to display ellipses for overflowing text. Wrapping content with specific width settings did not produce the desired result.
Another attempt with grid-template-columns resulted in the screen shrinking from left to right instead of utilizing the space between the N-1 and N columns.
The intended look on larger screens:
|Column A | |Column B| |Column C | |Column D|
|----------| |--------| |------------------| -------------------------------------------- |--------|
| Cell 1234| |Cell 2 | |Cell 5 | |Cell 6 |
| Cell 3 | |Cell 4 | |Cell 5555555555555| |Cell 6 |
Intermediate screen appearance:
|Column A | |Column B| |Column C | |Column D|
|----------| |--------| |------------------| --- |--------|
| Cell 1234| |Cell 2 | |Cell 5 | |Cell 6 |
| Cell 3 | |Cell 4 | |Cell 5555555555555| |Cell 6 |
On small screens:
|Column A | |Column B| |Column C | |Column D|
|----------| |--------| |---------| |--------|
| Cell 1234| |Cell 2 | |Cell 5 | |Cell 6 |
| Cell 3 | |Cell 4 | |Cell 5...| |Cell 6 |
And further minimized:
|Column A | |Column B| |Column C | |Column D|
|---------| |--------| |---------| |--------|
| Cell 1..| |Cell 2 | |Cell 5 | |Cell 6 |
| Cell 3 | |Cell 4 | |Cell 5...| |Cell 6 |
Is it possible to achieve this desired behavior?