如何在滑块下添加标题?

时间:2017-10-16 06:48:42

标签: javascript html css slider fade

我正在实现这个没有jquery的css3滑块。如何为滑块下方的每张幻灯片添加标题?

我正在研究这个问题: https://codepen.io/davidhc/pen/nLpJk

<div class='slider'>
  <div class='slide1'></div>
  <div class='slide2'></div>
  <div class='slide3'></div>
</div>

感谢您的帮助:)

3 个答案:

答案 0 :(得分:2)

请检查一下。我在幻灯片div中添加了标题,并将此css用于标题:

.slider p {
 left: 0;
 position: absolute;
 right: 0;
 text-align: center;
 top: 100%;
}

.slider {
  max-width: 300px;
  height: 200px;
  margin: 20px auto;
  position: relative;
}
.slide1,.slide2,.slide3,.slide4,.slide5 {
  position: absolute;
  width: 100%;
  height: 100%;
}
.slide1 {
  background: url(http://media.dunkedcdn.com/assets/prod/40946/580x0-9_cropped_1371566801_p17tbs0rrjqdt1u4dnk94fe4b63.jpg)no-repeat center;
  background-size: cover;
  animation:fade 8s infinite;
  -webkit-animation:fade 8s infinite;
} 
.slide2 {
  background: url(http://media.dunkedcdn.com/assets/prod/40946/580x0-9_cropped_1371565525_p17tbqpu0d69c21hetd77dh483.jpeg)no-repeat center;
  background-size: cover;
  animation:fade2 8s infinite;
  -webkit-animation:fade2 8s infinite;
}
.slide3 {
  background: url(http://media.dunkedcdn.com/assets/prod/40946/580x0-9_cropped_1371564896_p17tbq6n86jdo3ishhta3fv1i3.jpg)no-repeat center;
  background-size: cover;
  animation:fade3 8s infinite;
  -webkit-animation:fade3 8s infinite;
}
@keyframes fade
{
  0%   {opacity:1}
  33.333% { opacity: 0}
  66.666% { opacity: 0}
  100% { opacity: 1}
}
@keyframes fade2
{
  0%   {opacity:0}
  33.333% { opacity: 1}
  66.666% { opacity: 0 }
  100% { opacity: 0}
}
@keyframes fade3
{
  0%   {opacity:0}
  33.333% { opacity: 0}
  66.666% { opacity: 1}
  100% { opacity: 0}
}
.slider p {
  left: 0;
  position: absolute;
  right: 0;
  text-align: center;
  top: 100%;
}
<div class='slider'>
  <div class='slide1'><p>slide1</p></div>
  <div class='slide2'><p>slide2</p></div>
  <div class='slide3'><p>slide3</p></div>
</div>

答案 1 :(得分:0)

这是html,它适用于您的代码,但您必须通过css

设置样式
<div class='slider'>
  <div class='slide1'><div class="carl-caption">
     <h3>burger lover</h3>
     <p>Eat it pal</p>
  </div></div>
  <div class='slide2'><div class="carl-caption">
     <h3>dubai</h3>
     <p>dubai is wild</p>
  </div></div>
  <div class='slide3'><div class="carl-caption">
     <h3>gray land</h3>
     <p>imaginary land</p>
  </div></div>
</div>

for css caption试试这个

.slide1:after{content:"My name is lover";
      position: absolute;
      top: 0;
      right: 0;}

答案 2 :(得分:0)

我认为这就是你想要的。

    .slider {
  max-width: 300px;
  height: 200px;
  margin: 20px auto;
  position: relative;
}
.slide1,
.slide2,
.slide3,
.slide4,
.slide5 {
  position: absolute;
  width: 100%;
  height: 100%;
}
.slide1 {
  background: url(http://media.dunkedcdn.com/assets/prod/40946/580x0-9_cropped_1371566801_p17tbs0rrjqdt1u4dnk94fe4b63.jpg)no-repeat center;
  background-size: cover;
  animation: fade 8s infinite;
  -webkit-animation: fade 8s infinite;
}

.slide2 {
  background: url(http://media.dunkedcdn.com/assets/prod/40946/580x0-9_cropped_1371565525_p17tbqpu0d69c21hetd77dh483.jpeg)no-repeat center;
  background-size: cover;
  animation: fade2 8s infinite;
  -webkit-animation: fade2 8s infinite;
}
.slide3 {
  background: url(http://media.dunkedcdn.com/assets/prod/40946/580x0-9_cropped_1371564896_p17tbq6n86jdo3ishhta3fv1i3.jpg)no-repeat center;
  background-size: cover;
  animation: fade3 8s infinite;
  -webkit-animation: fade3 8s infinite;
}
@keyframes fade {
  0% {
    opacity: 1;
  }
  33.333% {
    opacity: 0;
  }
  66.666% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}
@keyframes fade2 {
  0% {
    opacity: 0;
  }
  33.333% {
    opacity: 1;
  }
  66.666% {
    opacity: 0;
  }
  100% {
    opacity: 0;
  }
}
@keyframes fade3 {
  0% {
    opacity: 0;
  }
  33.333% {
    opacity: 0;
  }
  66.666% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}
.slider p {
  left: 0;
  position: absolute;
  right: 0;
  text-align: center;
  top: 100%;
}

.slide1:after {
    position: absolute;
    content: "Slide one";
    bottom: -25px;
    width: 100%;
    text-align: center;
}
.slide2:after {
    position: absolute;
    content: "Slide Two";
    bottom: -25px;
    width: 100%;
    text-align: center;
}
.slide3:after {
    position: absolute;
    content: "Slide Three";
    bottom: -25px;
    width: 100%;
    text-align: center;
}
    <div class='slider'>
  <div class='slide1'></div>
  <div class='slide2'></div>
  <div class='slide3'></div>
</div>