CSS3 动画文本。停止内容结束

标签 css css-transitions css-animations

我试图将基于边框的光标停在动画文本的末尾,而不是移动到窗口的边缘。我已经尝试设置容器的宽度并调整文本宽度,但这将与未确定宽度的变量一起使用。

<div class="type">
    <h1>We have some basic text here</h1>
</div>


body { background: #333; font-family: "Lato"; color: #fff; }

div.type {
  text-align: center;
  color: #fff;
  white-space: nowrap;
}

.type h1 {
  overflow: hidden;
  border-right: .05em solid #aaa;
  width: auto;
  text-align: center;
  margin: 0 auto;
  animation:
    type 5s steps(100, end)
}

@keyframes type {
  from { width: 0; }
  to { width: 100%; }
}

Code Pen

最佳答案

使用最大宽度而不是宽度。

.type h1 {
  display: inline-block; <-- added
  overflow: hidden;
  border-right: .05em solid #aaa;
  max-width: auto;
  text-align: center;
  margin: 0 auto;
  animation:
    type 5s steps(100, end)
}

@keyframes type {
  from { max-width: 0; }
  to { max-width: 100%; }
}

Code Pen

关于CSS3 动画文本。停止内容结束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47421398/

相关文章:

html - 对齐 li 内的图像和文本 - 多行,限制空间

HTML/CSS - 从容器的右侧定位标签,到另一个标签的右侧

sproutcore - SC.SceneView 垂直动画?

html - CSS 动画 : squares loader

jquery - 如何根据屏幕大小调整页面上的 Div 大小?

CSS 菜单 : width of dropdown items limited by div

css - 使用背景图像并在其顶部应用 CSS 动画

html - 如何仅使用 CSS 获得悬停效果

css - 围绕 X 轴上的圆进行 3D 变换

css - 悬停时的@keyframes