html - 带有截断多行文本的 CSS 过渡
问题描述
我有以下代码片段:
如您所见,有一个截断的多行文本,如果单击它会展开。我还为 max-height 添加了一个过渡,以实现平稳移动。
input[type='checkbox'] {
display: none;
}
.flexbox {
display: flex;
flex-flow: row wrap;
background-color: green;
}
.lbl-toggle {
max-height: 30px;
transition: max-height 1s ease-in-out;
}
.truncate {
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
}
.toggle:checked+.lbl-toggle {
max-height: 350px;
}
.toggle:checked+.lbl-toggle>span {
text-overflow: initial;
overflow: initial;
white-space: initial;
}
<div>
<input id="collapsible" class="toggle" type="checkbox">
<label for="collapsible" class="flexbox lbl-toggle">
<span class="truncate">Text here is very very long that it might get truncate if this box get resized too small. Text here is very very long that it might get truncate if this box get resized too small</span>
</label>
</div>
但是,空白属性在与 max-height 和过渡的交互中产生了问题。只有最初的过渡有效,之后不再有效。我想如果我正在应用然后截断并white-space: nowrap
设置我的 max-height 不再应用并且过渡中断。
我唯一的想法是,当空白属性与 JS 一起应用时,我需要延迟。但是,我不想使用 JS。还有其他解决方案吗?
解决方案
遗憾的是,输入/输出转换的不一致max-height
是 CSS 中的一个众所周知的问题——这篇文章很好地解释了这个问题,并提供了一些可能有用的替代方案。
推荐阅读
- oracle - 保存后填充的 id 列与休眠返回值之间的差异
- node.js - 为什么我无法从 api 获得正确的值
- python - Python Try / except 在 Selenium 应用程序中执行的速度比应该慢
- javascript - 遍历循环,但在第二个循环中减少第一个数字,
- python - 在 Popen 之后终止进程及其所有子进程
- php - php 根据循环中的下一个 1 将二进制文件拆分/群集成块
- typescript - 为什么从对象查找分配时 TypeScript 不检查分配类型或未定义
- javascript - 显示一个对象 - 在 JavaScript/HTML 中单击另一个对象后
- matlab - 曲面图顶部的散点图有乱码
- c# - 如何使用 JSON.net 枚举嵌套的 JObject?