html - 如何使用CSS制作跑马灯样式

标签 html css marquee

我之前在我的快讯中使用了跑马灯元素,但因为它已被弃用,基于此 https://developer.mozilla.org/en-US/docs/Web/HTML/Element/marquee 我尝试改用 CSS。但是我遇到了一个问题,只显示了第一个 span 元素,而没有显示我的 span 元素的其余部分。

.flashnews_today {
  margin: 0 auto;
  white-space: nowrap;
  overflow: hidden;
  /*box-sizing: border-box;*/
  /*border: 1px green solid;*/
}

.flashnews_today span {
  display: inline-block;
  padding-left: 100%;
  text-indent: 0;
  /*border: 1px red solid;*/
  -webkit-animation: flashnews_today 45s linear infinite;
  animation: flashnews_today 45s linear infinite;
}

.flashnews_today span:hover {
  animation-play-state: paused
}


/* Make it move */

@keyframes flashnews_today {
  0% {
    transform: translate(0, 0);
  }
  100% {
    transform: translate(-100%, 0);
  }
}
<div class="flashnews_today">
  <span>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</span><span>Hello, I am a StackOverflow user. </span>
  <span>Hello, I am a StackOverflow user.</span>
  <span>Hello, I am a StackOverflow user. </span>
  <span>Hello, I am a StackOverflow user. </span>
  <span>Hello, I am a StackOverflow user. </span>
</div>

最佳答案

您的 CSS 引用了所有 span 标签,并试图在同一位置为它们设置动画。因此,只有第一个显示,同时防止其他显示。如果您在每个跨度之后使用 br 标签,您将看到您的其他跨度现在变得可见。

.flashnews_today {
  margin: 0 auto;
  white-space: nowrap;
  overflow: hidden;
  /*box-sizing: border-box;*/
  /*border: 1px green solid;*/
}

.flashnews_today span {
  display: inline-block;
  padding-left: 100%;
  text-indent: 0;
  /*border: 1px red solid;*/
  -webkit-animation: flashnews_today 45s linear infinite;
  animation: flashnews_today 45s linear infinite;
}

.flashnews_today span:hover {
  animation-play-state: paused
}


/* Make it move */

@keyframes flashnews_today {
  0% {
    transform: translate(0, 0);
  }
  100% {
    transform: translate(-100%, 0);
  }
}
<div class="flashnews_today">
  <span>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</span>
  <br/>
  <span>Hello, I am a StackOverflow user. </span>
  <br/>
  <span>Hello, I am a StackOverflow user.</span>
  <br/>
  <span>Hello, I am a StackOverflow user. </span>
  <br/>
  <span>Hello, I am a StackOverflow user. </span>
  <br/>
  <span>Hello, I am a StackOverflow user. </span>
</div>

关于html - 如何使用CSS制作跑马灯样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52362784/

相关文章:

php - 我无法将 1.5MB 以上的图像上传到服务器上的目录

javascript - 排序 HTML 表格长日期

javascript - 如何通过 JavaScript 插入 HTML 元素?

html - 类似字幕的垂直滚动文本(+停止)

android - 在同一 LinearLayout 中更改另一个 TextView 时,TextView 会重新启动 Marquee

c# - 在页面加载时禁用文本框

html - X-UA-Compatible 在包含在条件注释中时不起作用?

css - 如何申请子:hover but not parent:hover

javascript - 选择单选按钮并单击 'add' 按钮时不显示加载指示器

objective-c - 如何在iOS中制作字幕UILabel?