在我页面的一部分上,我使用 css3 过渡来显示/隐藏一些具有良好滑动效果的 div
.service_status {
max-height: 0;
-webkit-transition: max-height 1s ease-in-out;
-moz-transition: max-height 1s ease-in-out;
-ms-transition: max-height 1s ease-in-out;
-o-transition: max-height 1s ease-in-out;
transition: max-height 1s ease-in-out;
}
.service_status.open {
max-height: 500px;
-webkit-transition: max-height 1s ease-in-out;
-moz-transition: max-height 1s ease-in-out;
-ms-transition: max-height 1s ease-in-out;
-o-transition: max-height 1s ease-in-out;
transition: max-height 1s ease-in-out;
}
我想在某些表格行上使用相同的技术,但 max-height 和 height 没有任何效果(我猜是由于表格的 CSS 规范)。有没有一种方法可以仅使用 CSS3 过渡而不使用 js 来显示/隐藏带有动画的表格行?
原文由 wheresrhys 发布,翻译遵循 CC BY-SA 4.0 许可协议
恕我直言,这实现了流畅 的“全做” 解决方案。它不需要额外的 HTML 标记(除非非 div 块在表格中)并且可以处理我知道的所有棘手情况(甚至是边框折叠:分离)。
它基于@Tim Schoch 的’line-height’ 解决方案和@Vitox 的’div max-height’ 解决方案。所有解释都在 CSS 注释中。重复使用时,请设置所有三个过渡时间,并确保为表格单元格保存预设的最大高度。