There are search results stored in a table like the one below:
<table>
<tbody>
<tr>
<td>Column One</td>
<td>Column Two</td>
<td>Column Three</td>
</tr>
</tbody>
</table>
The actual table contains much more data (both in columns and rows) and is fluid width. Since the data is variable, I would like the table-layout
to remain auto
, because it handles autoresizing (which would be expensive and complicated to do in javascript for say 1,000 rows).
This table is also filtered by a live search widget which hides rows that do not match the query by adding display: none;
. However, I have found that this often causes the column widths to be recalculated (often causing some jarring jumps in column width). This makes sense, given that rows are likely only included calculations if they have display: table-row;
. But this is not the behavior I am after.
Is it possible to hide a <tr>
from view, but still have it included in column widths calculations done (on resize, for example) by the browser on a table with table-layout: auto;
?
I've tried setting height: 0;
(and max-height: 0;
), but have learned from other SO questions that this does not work because of display: table-cell;
. Similarly, Setting line-height: 0;
failed, but I figured it would since a few of my columns have block content.
I've also considered explicitly setting widths on the <td>
s, but then this makes keeping the table fluid (I would have to remove the explicit widths on resize, which could cause width jumps, and wouldn't work unless all of the rows were visible and included in the browser's table resize calculation).
Edit: To clarify, by hide from view I mean hide as in the sense of display: none;
, not visibility: hidden;
. The latter of which would work if the element did not retain it's original height when hidden, but unfortunately this is not the case.
Note: I know that upon first glance this appears to be a pretty narrowly applicable question, but I believe that this could be a common use case. As such, I've bolded the most applicable part (read: most important) of the question. The rest (which is slightly specific to me) is more explanatory than anything else.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…