情境:
如果用户将鼠标悬停在文本上(例如一个h1标签),它应该更改为新的文本。新文本应该平滑地出现。
到目前为止我做了什么:
我能够使用"display:none"和"content: 'This is the new text'"属性将文本替换为新文本。我的问题是,新文本不会平滑地出现(它没有淡入/过渡)。我也尝试过使用透明度,但它没有替换我的旧文本(而是只是消失,新文本出现在旁边)。
这里有一个JSFiddle和代码片段:
.my_div {
background-color: red;
}
.my_div:hover {
background-color: green;
transition: all 500ms ease-in-out;
}
.my_div:hover .title span {
display: none;
}
.my_div:hover .title:after {
content: "A wild text appears";
}
<div class="my_div">
<h1 class="title"><span>This is the old text</span></h1>
</div>