I am trying to implement a sliding animation for sub rows within a table structure. However, I have noticed that when using the div tag
within a table
, the animation does not work as expected compared to using the div
outside of the table
structure. The animation seems to be missing and it is formatting every sub td
in the first td
of the parent row.
You can find the source code for this issue in the following StackBlitz example
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr (click)="show = !show">
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<ng-container *ngIf="show">
<div class="box" [class.opened]="show">
<tr>
<td>Sam</td>
<td>Sample</td>
<td>35</td>
</tr>
<tr>
<tr>
<td>Piet</td>
<td>Miller</td>
<td>42</td>
</tr>
</div>
</ng-container>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
</table>
<div style="margin-top: 20px" class="box" [class.opened]="show">
Here the animation is working proper. <br> <br>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Neque ornare aenean euismod elementum nisi quis eleifend. Vivamus at augue eget arcu dictum. Dui sapien eget mi proin sed libero enim sed faucibus. Justo laoreet sit amet cursus sit amet dictum sit. Varius sit amet mattis vulputate. Lorem ipsum dolor sit amet consectetur adipiscing elit. Convallis tellus id interdum velit laoreet id donec ultrices. Tempus urna et pharetra pharetra massa massa. Tempor commodo ullamcorper a lacus vestibulum sed arcu non odio. Sagittis eu volutpat odio facilisis mauris sit amet massa vitae. Semper auctor neque vitae tempus quam pellentesque nec nam. Mauris nunc congue nisi vitae suscipit tellus mauris. Eget magna fermentum iaculis eu. Mi in nulla posuere sollicitudin. Nibh mauris cursus mattis molestie a iaculis at erat pellentesque. Nam libero justo laoreet sit amet. Aliquam faucibus purus in massa. Velit ut tortor pretium viverra suspendisse potenti nullam ac.
</div>
CSS
.box {
background-color: #FFCC55;
max-height: 0px;
overflow-y: hidden;
transition: ease-in-out 400ms max-height;
}
.box.opened {
max-height: 500px;
transition: ease-in-out 600ms max-height;
}