【发布时间】:2021-01-26 19:37:15
【问题描述】:
我想在光标悬停时显示全文,但仅在延迟 1 秒后显示。我尝试添加 transition 属性,但它似乎不适用于 absolute 元素。这是codepen demo。
代码如下:
.main {
display: flex;
justify-content: center;
}
.main .parent:hover .cell {
position: absolute !important;
z-index: 1 !important;
padding-right: 10px;
background: gray;
transition-delay: 1s;
}
.main .parent {
display: block;
width: 200px;
border-right: 1px solid rgb(237, 237, 236);
white-space: nowrap;
min-height: 32px;
cursor: default;
height: 32px;
padding: 5px 8px 6px;
font-size: 14px;
overflow: hidden;
}
.main .parent .cell {
line-height: 1.5;
white-space: nowrap;
word-break: normal;
pointer-events: none;
}
<main class="main">
<div class="parent">
<span class="cell">
In publishing and graphic design, Lorem ipsum is a placeholder text
commonly used to demonstrate the visual form of a document or a typeface
without relying on meaningful content.</span
>
</div>
</main>
请注意,背景颜色正在正确过渡,但当我悬停时会立即显示全文。
正在寻找一种解决方案,在不使用任何 JavaScript 的情况下增加显示全文的延迟。
【问题讨论】:
-
这是您要找的东西吗? stackoverflow.com/questions/30089444/…
-
不,这个问题是关于改变颜色的,我问的是在悬停时显示全文时添加延迟。
-
您使用哪个属性来显示文本? z-index,溢出?
-
"那个问题是关于改变颜色的";所以...用你想要转换的属性交换颜色。您没有指定任何要转换的属性(
transition-property);这就是它当前没有转换的原因(您仅指定了延迟)。 -
看起来您正在使用
overflow属性来显示文本 - 这是分配给容器的属性,而不是文本。您是否尝试过将鼠标悬停在容器上?