gpt4 book ai didi

css - 文本在悬停 CSS 上滑入

转载 作者:行者123 更新时间:2023-12-03 21:54:13 25 4
gpt4 key购买 nike

我要文字 Along came鼠标悬停时滑入 the wolf .
但是the wolf的位置不应该改变。 Along came应该简单地从左侧滑入并淡入以完成句子。

.main {
width: 100vw;
text-align:center;
}

.addText {
display: none;
color: rgba(255,255,255,0);
transition: .5s;
}

.link:hover .addText {
display: inline;
color: red;
transform: translate(-10px, 00%);
}
<div class="main">
<div class="link">
<span class="addText">Along came </span>
the wolf
</div>
</div>

最佳答案

这是一个想法,您可以在其中制作元素 width:0所以它不会影响其他元素:

.main {
text-align:center;
}
.link {
display:inline-block;
}
.addText {
display:inline-block; /* inline-block so we can set a width */
width:0;
white-space:nowrap; /* keep text one line */
direction:rtl; /* change direction so the text overflow on the left */
color: rgba(255,255,255,0);
transition: .5s;
transform: translateX(20px); /* put the value you want here */
pointer-events:none; /* to avoid the hover on the text, remove to see the difference */
}

.link:hover .addText {
color: red;
transform: translateX(0);
}
<div class="main">
<div class="link">
<span class="addText">Along came </span>
the wolf
</div>
</div>


如果您希望文本占用空间,您也可以只进行翻译:

.main {
text-align:center;
}
.link {
display:inline-block;
}
.addText {
display:inline-block;
color: rgba(255,255,255,0);
transition: .5s;
transform: translateX(100%);
}

.link:hover .addText {
color: red;
transform: translateX(0);
}
<div class="main">
<div class="link">
<span class="addText">Along came </span>
the wolf
</div>
</div>

关于css - 文本在悬停 CSS 上滑入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62073617/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com