html - 幻灯片无法正常工作

标签 html css css-animations

我在较早的代码中使用了相同的@keyframes,但效果很好,不知道为什么这里不能正常工作,幻灯片无法平稳移动,并且展示柜的第四个子卡在左侧,并且是唯一一个正在覆盖width: 100%



body {margin: 0}

.top-container {
  display: grid;
  grid-template-areas:
  'showcase showcase'
  'showcase showcase';
}

.showcase {
  grid-area: showcase;
  min-height: 600px;
  width: 100%;
  padding: 3rem;
  display: flex;
  flex-direction: column;
  align-items: start;
  justify-content: center;
  box-shadow: var(--shadow);
  animation: slide 8s infinite;
}

.showcase h1 {
  font-size: 4rem;
  margin-bottom: 0;
  color: var(--light);
}

.showcase:nth-child(1) {
  animation-delay: -1s;
  background-color: #333;
  background-size: cover;
  background-position: center;
}

.showcase:nth-child(2) {
  animation-delay: 2s;
  background-color: black;
  background-size: cover;
  background-position: center;
}

.showcase:nth-child(3) {
  animation-delay: 5s;
  background-color: bisque;
  background-size: cover;
  background-position: center;
}

.showcase:nth-child(4) {
  animation-delay: 8s;
  background-color: yellowgreen;
  background-size: cover;
  background-position: center;
}

@keyframes slide {
  0% {left: 100%; width: 100%}
  5% {left: 0%}
  25% {left: 0%}
  30% {left: -100%; width: 100%}
  30.01% {left: -100%; width: 0%}
  100% {left: 100%; width: 0%}
}

<section class="top-container">
  <div class="showcase">1</div>
  <div class="showcase">2</div>
  <div class="showcase">3</div>
  <div class="showcase">4</div>
</section>

最佳答案

出现问题的主要原因是,尽管没有在left类中设置position: absolute;,但您仍在使用.showcase属性。
修复后,应注意z-index中的@keyframes slide属性

关于html - 幻灯片无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50873773/

相关文章:

html - 在进度条背景上居中进度值

css - 匹配css中重复线性渐变模式的开始和结束

html - Bootstrap 如何更改表格中链接的样式?

javascript - 为什么JavaScript引起的CSS样式变化在脚本运行结束后不会保留?

css - 字体图标 IE 8 问题

html - 单击时链接被移动(CSS)?

html - 多个关键帧动画

javascript - 转换图像上的无限动画

html - 即使在浏览器调整大小时也制作粘性页脚

html - 我需要删除分割 block 之间的一点空间