我希望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%);
}Run Code Online (Sandbox Code Playgroud)
<div class="main">
<div class="link">
<span class="addText">Along came </span>
the wolf
</div>
</div>Run Code Online (Sandbox Code Playgroud)
这是一个想法,您可以在其中制作元素,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);
}Run Code Online (Sandbox Code Playgroud)
<div class="main">
<div class="link">
<span class="addText">Along came </span>
the wolf
</div>
</div>Run Code Online (Sandbox Code Playgroud)
如果您希望文本占用空间,您也可以只进行翻译:
.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);
}Run Code Online (Sandbox Code Playgroud)
<div class="main">
<div class="link">
<span class="addText">Along came </span>
the wolf
</div>
</div>Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
115 次 |
| 最近记录: |