悬停CSS上的文本幻灯片

问题描述 投票:1回答:1

当鼠标悬停在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>
css hover slide
1个回答
2
投票

这里是您可以制作元素width:0的概念,这样它就不会影响其他元素:

.main {
  text-align:center;
}
.link {
  display:inline-block; 
}
.addText {
  display:inline-block; /* inline-block so we can set a widrh */
  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 */
}

.link:hover .addText {
  color: red;
  transform: translateX(0);
}
<div class="main">
  <div class="link">
      <span class="addText">Along came </span>
      the wolf
  </div>
</div>
© www.soinside.com 2019 - 2024. All rights reserved.