如何将此滑块调整到特定 height/width

How to adjust this slider to a specific height/width

我正在关注本教程的响应式图像幻灯片放映,我在进入教程时认为我可以将幻灯片放映的大小调整到特定的高度和宽度,使其变小并适应我想要的想法做。可悲的是,我被卡住了,想不出办法,所以我来到这里希望能解决这个问题。

这是我正在尝试做的事情的图片

这是我的HTML

.slide-container {
    position: relative;
    width: 100%;
    height: 100vh;
    overflow: hidden;
}

.slide-container .slider {
    position: absolute;
    top: 0;
    left: 0;
    width: 500%;
    height: 100%;
    float: left;
    animation: animate 10s linear infinite;
    
}
    
.slide-container .slider .slide {
    position: relative;
    width: 20%;
    height: 100%;
    float : left;
}
    
.slide-container .slider .slide .caption{
    position: absolute;
    bottom: 60px;
    left: 60px;
    right: 60px;
    padding: 30px;
    background: rgba(0,0,0,0.5);
    box-sizing: border-box;
}

.slide-container .slider .slide .caption h2 {
    margin: 0 0 20px;
    padding: 0;
    color: white;
    font-size: 48px;
}

.slide-container .slider .slide .caption p {
    margin: 0;
    padding: 0;
    color: white;
    font-size: 18px;
}

.slide-container .slider .slide.slide1 {
    background: url(../images/heroImage2.jpg);
    background-size: cover;
    background-position: center;
}

.slide-container .slider .slide.slide2 {
    background: url(../images/heroImage.jpg);
    background-size: cover;
    background-position: center;
}

.slide-container .slider .slide.slide3 {
    background: url(../images/heroImage2.jpg);
    background-size: cover;
    background-position: center;
}

.slide-container .slider .slide.slide4 {
    background: url(../images/heroImage2.jpg);
    background-size: cover;
    background-position: center;
}

@keyframes animate {
    0% 
    {
        left: 0;
    }
    
    20% 
    {
        left: 0;
    }
    
    25% 
    {
        left: -100%;
    }
    
    45% 
    {
        left: -100%;
    }
    50% 
    {
        left: -200%;
    }
    70% 
    {
        left: -200%;
    }
    75% 
    {
        left: -300%;
    }
    95% 
    {
        left: -300%;
    }
    100% {
        left: -400%;
    }
}

@media (max-width: 768px) {
    .slide-container .slider .slide .caption{
    bottom: 20px;
    left: 20px;
    right: 20px;
    padding: 20px;
    background: rgba(0,0,0,0.5);
    box-sizing: border-box;
  }

  .slide-container .slider .slide .caption h2 {
    margin: 0 0 10px;
    font-size: 30px;
  }

  .slide-container .slider .slide .caption p {
    font-size: 16px;
  }

}
<div class="slide-container">
    <div class="slider">
        <div class="slide slide1">
            <div class="caption">
                <h2>Slide1</h2>
                <p>Test</p>
            </div>
        </div>
        <div class="slide slide2">
            <div class="caption">
                <h2>Slide2</h2>
                <p>Test</p>
            </div>
        </div>
        <div class="slide slide3">
            <div class="caption">
                <h2>Slide3</h2>
                <p>Test</p>
            </div>
        </div>
        <div class="slide slide4">
            <div class="caption">
                <h2>Slide4</h2>
                <p>Test</p>
            </div>
        </div>
    </div>
</div>

您可以使用弹性容器并最终设置动画延迟,这样它们就不会同时开始。

可能的例子,如果我理解。

body{margin:0;}

section {
  display: flex;
  height: 100vh;
  gap: 5vw;
  padding: 5vw;
  box-sizing: border-box;
}

.slide-container {
  position: relative;
  flex-grow: 1;
  background:lightgray;
  overflow: hidden;
}

.slide-container .slider {
  position: absolute;
  top: 0;
  left: 0;
  width: 500%;
  height: 100%;
  float: left;
  animation: animate 10s linear infinite;
  }

.slide-container  + .slide-container .slider {
animation-delay:-3.3s;
}.slide-container  +.slide-container  + .slide-container .slider {
animation-delay:-6.6s;
}

.slide-container .slider .slide {
  position: relative;
  width: 20%;
  height: 100%;
  float: left;
}

.slide-container .slider .slide .caption {
  position: absolute;
  bottom: 6px;
  left: 6px;
  right: 6px;
  padding: 3px;
  background: rgba(0, 0, 0, 0.5);
  box-sizing: border-box;
}

.slide-container .slider .slide .caption h2 {
  margin: 0 0 20px;
  padding: 0;
  color: white;
  font-size: 48px;
}

.slide-container .slider .slide .caption p {
  margin: 0;
  padding: 0;
  color: white;
  font-size: 18px;
}

.slide-container .slider .slide.slide1 {
  background: url(https://picsum.photos/id/1012/400/280);
  background-size: cover;
  background-position: center;
}

.slide-container .slider .slide.slide2 {
  background:  url(https://picsum.photos/id/1014/400/280);
  background-size: cover;
  background-position: center;
}

.slide-container .slider .slide.slide3 {
  background:  url(https://picsum.photos/id/1016/400/280);
  background-size: cover;
  background-position: center;
}

.slide-container .slider .slide.slide4 {
  background:  url(https://picsum.photos/id/1018/400/280);
  background-size: cover;
  background-position: center;
}

@keyframes animate {
  0% {
    left: 0;
  }
  20% {
    left: 0;
  }
  25% {
    left: -100%;
  }
  45% {
    left: -100%;
  }
  50% {
    left: -200%;
  }
  70% {
    left: -200%;
  }
  75% {
    left: -300%;
  }
  95% {
    left: -300%;
  }
  100% {
    left: -400%;
  }
}

@media (max-width: 768px) {
  .slide-container .slider .slide .caption {
    bottom: 20px;
    left: 20px;
    right: 20px;
    padding: 20px;
    background: rgba(0, 0, 0, 0.5);
    box-sizing: border-box;
  }
  .slide-container .slider .slide .caption h2 {
    margin: 0 0 10px;
    font-size: 30px;
  }
  .slide-container .slider .slide .caption p {
    font-size: 16px;
  }
}
<section>
  <div class="slide-container">
    <div class="slider">
      <div class="slide slide1">
        <div class="caption">
          <h2>Slide1</h2>
          <p>Test</p>
        </div>
      </div>
      <div class="slide slide2">
        <div class="caption">
          <h2>Slide2</h2>
          <p>Test</p>
        </div>
      </div>
      <div class="slide slide3">
        <div class="caption">
          <h2>Slide3</h2>
          <p>Test</p>
        </div>
      </div>
      <div class="slide slide4">
        <div class="caption">
          <h2>Slide4</h2>
          <p>Test</p>
        </div>
      </div>
    </div>
  </div>
  <div class="slide-container">
    <div class="slider">
      <div class="slide slide1">
        <div class="caption">
          <h2>Slide1</h2>
          <p>Test</p>
        </div>
      </div>
      <div class="slide slide2">
        <div class="caption">
          <h2>Slide2</h2>
          <p>Test</p>
        </div>
      </div>
      <div class="slide slide3">
        <div class="caption">
          <h2>Slide3</h2>
          <p>Test</p>
        </div>
      </div>
      <div class="slide slide4">
        <div class="caption">
          <h2>Slide4</h2>
          <p>Test</p>
        </div>
      </div>
    </div>
  </div>
  <div class="slide-container">
    <div class="slider">
      <div class="slide slide1">
        <div class="caption">
          <h2>Slide1</h2>
          <p>Test</p>
        </div>
      </div>
      <div class="slide slide2">
        <div class="caption">
          <h2>Slide2</h2>
          <p>Test</p>
        </div>
      </div>
      <div class="slide slide3">
        <div class="caption">
          <h2>Slide3</h2>
          <p>Test</p>
        </div>
      </div>
      <div class="slide slide4">
        <div class="caption">
          <h2>Slide4</h2>
          <p>Test</p>
        </div>
      </div>
    </div>
  </div>
</section>