【发布时间】:2019-08-21 07:44:22
【问题描述】:
我有以下代码snippet:
如您所见,有一个截断的多行文本,如果单击它会展开。我还为 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>
但是,whitespace-property 在与 max-height 和过渡的交互方面存在问题。只有最初的过渡有效,之后不再有效。我想如果我正在应用,那么截断并设置white-space: nowrap 我的 max-height 不再应用并且转换中断。
我唯一的想法是,当空白属性与 JS 一起应用时,我需要延迟。但是,我不想使用 JS。还有其他解决方案吗?
【问题讨论】:
-
你不想使用 JS 有确切的理由吗?请注意,在这里它适用于第一次之后的扩展过渡,但只是您需要在最小化标签后等待整整一秒钟(max-height 1s ease-in-out;)。如果没有转换最小化是正常的,因为
white-space: nowrap可能会影响height而不是max-height
标签: html css whitespace transition