I've been searching SO for a while and haven't found a similar solution. I'm trying create a table in a web page that would have the following characteristics:
- Table width = 100% always (no scroll is needed to see all columns; table takes all the available width)
- Table cells are compacted (e.g.: no extra space is used unless necessary)
- If cells are too wide, crop and use ellipsis.
- All cells are 1 line height
- I don't know how many columns will be shown (could be ~40) - which I believe rules out
max-width
for the cells?
One solution I saw in this question uses inner <table />
s but playing with the suggested fiddle you can tell fields aren't compacted (see here).
EDIT: I'm using Knockout so my table structure goes as follows (Note I don't know how many columns are showing):
<table class="grid">
<thead>
<tr data-bind="foreach: columns">
<th data-bind="text: name" />
</tr>
</thead>
<tbody data-bind="foreach: rows">
<tr data-bind="foreach: $data">
<td data-bind="text: $data" />
</tr>
</tbody>
</table
The current CSS (that doesn't work so anything is welcome):
.grid tr td {
white-space: nowrap;
overflow: hidden;
-ms-text-overflow: ellipsis;
-o-text-overflow: ellipsis;
text-overflow: ellipsis;
}
EDIT 2: Adding a Fiddle
Ideas? Links? Dups?