I'm trying to do something very simple: get the height of a tr
to 0px
, but it won't work.
See the code or this JSFiddle for what I've tried.
HTML:
<table>
<tbody>
<tr>
<td>
Title 1
</td>
<td>
Title 2
</td>
</tr>
<tr class="model">
<td>
<input placeholder="Name">
</td>
<td>
<input class="delete" type="checkbox">
</td>
</tr>
</table>
CSS:
.model, .model * {
max-height: 0 !important;
min-height: 0 !important;
height: 0 !important;
margin-top: 0 !important;
margin-bottom: 0 !important;
padding-top: 0 !important;
padding-bottom: 0 !important;
border-top: 0 !important;
border-bottom: 0 !important;
outline: 0 !important;
}
.model {
background-color: red;
}
RESULT:
There is red in the result, so the tr
height is still not 0.
How can I get it to be 0, while maintaining the width?
EDIT: The issue seems to be the checkbox
nested into the td
. How can I get its height down to 0?
The height of rows 'tr' in a table can be fixed very easily. This can be done by adding the height attribute in the tr tag. If the height is not specified, the height of the row changes according to the content. The height can be specified either in pixels, or percentage.
To set the cell width and height, use the CSS style. The height and width attribute of the <td> cell isn't supported in HTML5. Use the CSS property width and height to set the width and height of the cell respectively.
Change row height To set the row height to a specific measurement, click a cell in the row that you want to resize. On the Layout tab, in the Cell Size group, click in the Table Row Height box, and then specify the height you want. To use the ruler, select a cell in the table, and then drag the markers on the ruler.
I would add visibility: collapse;
to tr
to fix that
Wrap it in a DIV
, set it to not be tall enough, hide the overflow
:
div {
height: 1.2em;
overflow: hidden;
}
I know I'm late to the party, but I had the same problem with a Bootstrap 3 table. Looking in Chrome inspector, it looks like the bootstrap css selectors are very specific, so they seem to take precedence over my css unless I am even more specific. So while the following did not work:
tr.my-class td {
height: 0;
padding: 0;
border-top: 0;
overflow: hidden;
line-height: 0;
transition: all ease 0.5s;
}
tr.my-class.expanded td {
height: 20px;
padding: 5px;
border-top: 1px solid #ddd;
line-height: 20px;
}
Changing it to this to mirror the Bootstrap selectors worked:
table>tbody>tr.my-class>td {
height: 0;
padding: 0;
border-top: 0;
overflow: hidden;
line-height: 0;
transition: all ease 0.5s;
}
table>tbody>tr.my-class.expanded>td {
height: 20px;
padding: 5px;
border-top: 1px solid #ddd;
line-height: 20px;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With