This is great, but I use angular, and the problem is that if I have more lines, I have no room for it vertically.
What does angular have to do with this?
[..] If I have more lines, I have no place for it vertically. Instead, I want to "overflow" to the right of it.
Tables do not give you such flexibility, especially, you will not be able to control the height and flow of rows in the form of columns.
[..] so that I can make the content spill if it exceeds the table? Please note that in some cases I may have 2 or 3 entries, so I am hoping that I do not need to make the width twice as large as start, and instead the table will be sized based on the number of entries that I have in the table.
One simple and quick way would be to split your rows into your own tables. If you can have this structure, then this is just a question using CSS columns .
Typically, you wrap all of these tables in a div that will have height restrictions. Set the column-* properties on the wrapper div , and there you go. You can play with column-gap , column-rule , column-span and column-fill properties to decorate the whole thing.
Also note that you will need to use break-inside: avoid in tables to avoid breaking them halfway, moving on to the next column.
Fragment example:
#rowflow { height: 120px; max-height: 120px; border: 1px solid #d33; overflow: hidden; column-width: 200px; column-gap-width: 0px; column-fill: auto; column-rule: 1px solid #bbb; } table { font-family: sans-serif; margin-bottom: 2px; table-layout: fixed; width: 190px; } table:first-child { column-span: all; } table, th, td { border-collapse: collapse; border: 0px solid gray; padding: 6px; } table, tr { break-inside: avoid; } th, td { text-align: left; } th:last-child, td:last-child { text-align: right; }
<div id="rowflow"> <table><tr><th>Name</th><th>Sport</th><th>Score</th></tr></table> <table><tr><td>Jordan</td><td>Soccer</td><td>50</td></tr></table> <table><tr><td>Jordan</td><td>Soccer</td><td>50</td></tr></table> <table><tr><td>Jordan</td><td>Soccer</td><td>50</td></tr></table> <table><tr><td>Jordan</td><td>Soccer</td><td>50</td></tr></table> <table><tr><td>Jordan</td><td>Soccer</td><td>50</td></tr></table> </div>
In the above snippet, the div wrapper is limited in height and you can see the columns flow.
Use this script to try resizing the window and see the effect.
[..], so I hope that I do not need to make the width twice as normal at the beginning, and instead the table should be calculated based on the number of records that I have in the table. No scrollbars.
The wrapper div will be fully populated. However, you can twist using overflow to control overflow handling. Changing the width dynamically, based on the width of the content, is a completely different ball game in which you need JavaScript, and it gets messy.
Note. . In the above example, you will need to fix the width of your tables so that the columns are neatly aligned. You can use table-layout: fixed to use a fixed layout.